opengraph

package module
v0.0.0-...-d2ea73d Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2015 License: MIT Imports: 3 Imported by: 0

README

Open Graph protocol opengraph

opengraph is a Go library for extracting Open Graph metadata from html documents.

Documentation: http://godoc.org/github.com/rojters/opengraph
Open Graph protocol: http://ogp.me/
Build Status: travis-ci status Build Status

Usage

import "github.com/rojters/opengraph"

To extract Open Graph metadata from a movie on IMDb:

res, _ := http.Get("http://www.imdb.com/title/tt0118715/")
og, _ := opengraph.Extract(res.Body)
for _, md := range og {
	fmt.Printf("%s = %s\n", md.Property, md.Content)
}

Which will output:

url = http://www.imdb.com/title/tt0118715/
type = video.movie
title = The Big Lebowski (1998)
site_name = IMDb
description = Directed by Joel Coen, Ethan Coen.  With Jeff Bridges ...
...

License

MIT

Documentation

Overview

Package opengraph extracts Open Graph metadata from html documents. See http://ogp.me/ for more information about the Open Graph protocol.

Usage:

import "github.com/rojters/opengraph"

To extract Open Graph metadata from a movie on IMDb:

res, _ := http.Get("http://www.imdb.com/title/tt0118715/")
og, _ := opengraph.Extract(res.Body)
for _, md := range og {
	fmt.Printf("%s = %s\n", md.Property, md.Content)
}

Which will output:

url = http://www.imdb.com/title/tt0118715/
type = video.movie
title = The Big Lebowski (1998)
site_name = IMDb
description = Directed by Joel Coen, Ethan Coen.  With Jeff Bridges ...
...

Index

Constants

This section is empty.

Variables

View Source
var Namespace = "og:"

By default Extract will only return metadata in the Open Graph namespace. This variable can be changed to get data from other namespaces. Ex: 'fb:' for Facebook or to get all metadata regardless of namespace, set it to the empty string.

Functions

This section is empty.

Types

type MetaData

type MetaData struct {
	Property string // Porperty attribute without namespace prefix.
	Content  string // See http://ogp.me/#data_types for a list of content attribute types.
}

func Extract

func Extract(doc io.Reader) ([]MetaData, error)

Extract extracts Open Graph metadata from a html document. If no relevant metadata is found the result will be empty. The input is assumed to be UTF-8 encoded.

Jump to

Keyboard shortcuts

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