Documentation
¶
Overview ¶
Package opengraph implements and parses "The Open Graph Protocol" of web pages. See http://ogp.me/ for more information.
Index ¶
Examples ¶
Constants ¶
const ( // HTMLLinkTag is a tag name of <link> HTMLLinkTag string = "link" // HTMLMetaTag is a tag name of <meta> HTMLMetaTag string = "meta" // HTMLTitleTag is a tag name of <title> HTMLTitleTag string = "title" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Link ¶
Link represents any "<link ...>" HTML tag
func (*Link) Contribute ¶
Contribute contributes OpenGraph
type Meta ¶
Meta represents any "<meta ...>" HTML tag.
func (*Meta) IsDescription ¶
IsDescription returns if it can be "description" of OGP
func (*Meta) IsImageProperty ¶
IsImageProperty returns if it can be a property of "og:image" struct
func (*Meta) IsOGDescription ¶ added in v1.1.0
IsOGDescription returns if it can be "description" of OGP
func (*Meta) IsSiteName ¶
IsSiteName returns if it can be "og:site_name"
type OpenGraph ¶
type OpenGraph struct {
// Policy specifies a policy to parse HTML document.
Policy struct {
TrustedTags []string
}
// Basics
Title string
Type string
URL URL
SiteName string
// Structures
Image []*OGImage
Video []*OGVideo
Audio []*OGAudio
// Optionals
Description string
Determiner string // TODO: enum?
Locale string
LocaleAlt []string
// Additionals
Favicon string
// Utils
HTTPClient *http.Client `json:"-"`
Error error `json:"-"`
}
OpenGraph represents web page information according to OGP <ogp.me>, and some more additional informations like URL.Host and so.
func Fetch ¶
Fetch creates and parses OpenGraph with specified URL.
Example ¶
ogp, _ := Fetch("https://github.com/otiai10/gosseract")
fmt.Println(ogp.Title)
Output: otiai10/gosseract
func FetchWithContext ¶ added in v1.1.0
func FetchWithContext(ctx context.Context, rawurl string, customHTTPClient ...*http.Client) (*OpenGraph, error)
FetchWithContext creates and parses OpenGraph with specified URL. Timeout can be handled with provided context.
func (*OpenGraph) Parse ¶
Parse parses http.Response.Body and construct OpenGraph informations. Caller should close body after it get parsed.
Example ¶
client := http.DefaultClient
res, err := client.Get("https://github.com/otiai10/amesh")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
ogp := new(OpenGraph)
ogp.Parse(res.Body)
fmt.Println(ogp.Title)
Output: otiai10/amesh
type Title ¶
type Title struct {
Text string
}
Title represents any "<title ...>" HTML tag.
func (*Title) Contribute ¶
Contribute contributes to OpenGraph