Categorygithub.com/otiai10/opengraph/v2
modulepackage
2.1.0
Repository: https://github.com/otiai10/opengraph.git
Documentation: pkg.go.dev

# README

Open Graph Parser for Golang

Go implementation of https://ogp.me/

reference Go codecov Maintainability Go Report Card License: MIT FOSSA Status GitHub tag (latest SemVer)

Code Example

package main

import (
	"fmt"
	"github.com/otiai10/opengraph/v2"
)

func main() {
	ogp, err := opengraph.Fetch("https://github.com/")
	fmt.Println(ogp, err)
}

You can try CLI as a working example

% go get github.com/otiai10/opengraph/ogp
% ogp --help
% ogp -A otiai10.com

Just for fun 😉

Advanced usage

Set an option for fetching:

intent := opengraph.Intent{
	Context:     ctx,
	HTTPClient:  client,
	Strict:      true,
	TrustedTags: []string{"meta", "title"},
}
ogp, err := opengraph.Fetch("https://ogp.me", intent)

Use any io.Reader as a data source:

f, _ := os.Open("my_test.html")
defer f.Close()
ogp := &opengraph.OpenGraph{}
err := ogp.Parse(f)

or if you already have parsed *html.Node:

err := ogp.Walk(node)

Do you wanna make absolute URLs?:

ogp.Image[0].URL // /logo.png
ogp.ToAbs()
ogp.Image[0].URL // https://ogp.me/logo.png

Issues

# Packages

No description provided by the author

# Functions

Fetch creates and parses OpenGraph with specified URL.
LinkTag constructs Link.
MetaTag constructs MetaTag.
New constructs new OpenGraph struct and fill nullable fields.
TitleTag constructs Title.

# Constants

HTMLLinkTag is a tag name of <link>.
HTMLMetaTag is a tag name of <meta>.
HTMLTitleTag is a tag name of <title>.

# Structs

Audio represents a structure of "og:audio".
Favicon represents an extra structure for "shortcut icon".
Image represents a structure of "og:image".
Intent represents how to fetch, parse, and complete properties of this OpenGraph object.
Link represents any "<link ...>" HTML tag.
Meta represents any "<meta ...>" HTML tag.
OpenGraph represents web page information according to OGP <ogp.me>, and some more additional informations like URL.Host and so.
Title represents any "<title ...>" HTML tag.
Video represents a structure of "og:video".