opengraph

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2017 License: MIT Imports: 9 Imported by: 0

README

Open Graph Parser for Golang

Build Status GoDoc

Code Example

package main

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

func main() {
	og, err := opengraph.Fetch("http://github.com/otiai10/too")
	fmt.Printf("OpenGraph: %+v\nError: %v\n", og, err)
}

cli as a working example

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

For more details, see ogp/main.go.

advanced

Documentation

Overview

Package opengraph implements and parses "The Open Graph Protocol" of web pages. See http://ogp.me/ for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	Rel  string
	Href string
}

Link represents any "<link ...>" HTML tag

func LinkTag

func LinkTag(n *html.Node) *Link

LinkTag constructs Link

func (*Link) Contribute

func (link *Link) Contribute(og *OpenGraph) error

Contribute contributes OpenGraph

func (*Link) IsFavicon

func (link *Link) IsFavicon() bool

IsFavicon returns if it can be "favicon" of *opengraph.OpenGraph

type Meta

type Meta struct {
	Name     string
	Property string
	Content  string
}

Meta represents any "<meta ...>" HTML tag.

func MetaTag

func MetaTag(n *html.Node) *Meta

MetaTag constructs MetaTag.

func (*Meta) Contribute

func (m *Meta) Contribute(og *OpenGraph) error

Contribute ...

func (*Meta) IsDescription

func (m *Meta) IsDescription() bool

IsDescription returns if it can be "description" of OGP

func (*Meta) IsImage

func (m *Meta) IsImage() bool

IsImage returns if it can be a root of "og:image"

func (*Meta) IsImageProperty

func (m *Meta) IsImageProperty() bool

IsImageProperty retuns if it can be a property of "og:image" struct

func (*Meta) IsSiteName

func (m *Meta) IsSiteName() bool

IsSiteName returns if it can be "og:site_name"

func (*Meta) IsTitle

func (m *Meta) IsTitle() bool

IsTitle returns if it can be "title" of OGP

func (*Meta) IsType

func (m *Meta) IsType() bool

IsType returns if it can be "og:type"

type OGAudio

type OGAudio struct {
	URL  string
	SURL string
	Type string
}

OGAudio represents "og:audio" structure.

type OGImage

type OGImage struct {
	URL    string
	SURL   string
	Type   string
	Width  int
	Height int
	Alt    string
}

OGImage represents "og:image" structure.

type OGVideo

type OGVideo struct {
	URL    string
	SURL   string
	Type   string
	Width  int
	Height int
}

OGVideo represents "og:video" structure.

type OpenGraph

type OpenGraph struct {

	// 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

func Fetch(rawurl string, customHTTPClient ...*http.Client) (*OpenGraph, error)

Fetch creates and parses OpenGraph with specified URL.

func New

func New(rawurl string) *OpenGraph

New creates new OpenGraph struct with specified URL.

func (*OpenGraph) Fulfill

func (og *OpenGraph) Fulfill() error

Fulfill fulfills OG informations with some expectations.

func (*OpenGraph) Parse

func (og *OpenGraph) Parse(body io.Reader) error

Parse parses http.Response.Body and construct OpenGraph informations. Caller should close body after it get parsed.

func (*OpenGraph) ToAbsURL

func (og *OpenGraph) ToAbsURL() *OpenGraph

ToAbsURL make og.Image and og.Favicon absolute URL if relative.

type Title

type Title struct {
	Text string
}

Title represents any "<title ...>" HTML tag.

func TitleTag

func TitleTag(n *html.Node) *Title

TitleTag constructs Title.

func (*Title) Contribute

func (t *Title) Contribute(og *OpenGraph) error

Contribute contributes to OpenGraph

type URL

type URL struct {
	Source string
	*url.URL
}

URL includes *url.URL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL