googp is an OGP (Open Graph protocol) parser library for Golang.
- 💯 Fully compliant with the reference
- 🔧 Highly customizable
- Available your own structs
- Available parsing your own OG Tags.
- 🙌 Supports type conversion
- Supports all types that implement encoding.TextUnmarshaler.
To install it, run:
go get -u github.com/soranoba/googp
import (
"fmt"
"github.com/soranoba/googp"
)
type Music struct {
}
type CustomOGP struct {
Title string `googp:"og:title"`
Description string `googp:"-"` // ignored
images []string // private field (ignored)
Videos []string `googp:"og:video,og:video:url"`
Musics Music `googp:"music"` // object type
}
func main() {
var ogp1 googp.OGP
if err := googp.Fetch("https://soranoba.net", &ogp1); err != nil {
return
}
fmt.Println(ogp1)
var ogp2 CustomOGP
if err := googp.Fetch("https://soranoba.net", &ogp2); err != nil {
return
}
fmt.Println(ogp2)
}
type OGP struct {
Image struct {
URL string `googp:"og:image,og:image:url"`
SecureURL string `googp:"og:image:secure_url"`
} `googp:"og:image"`
}
You may collect in a struct by specifying the root tag.
In case of specifying og:image
, googp collect values which property is og:image:*
.
type OGP struct {
Image []string `googp:"og:image"`
}
googp collects values which the same properties.
In googp, it same as Structured Properties.
You may define your own type yourself.