Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/otiai10/opengraph
Open Graph Parser for Go
https://github.com/otiai10/opengraph
go html ogp ogp-image ogp-meta ogp-tags
Last synced: 13 days ago
JSON representation
Open Graph Parser for Go
- Host: GitHub
- URL: https://github.com/otiai10/opengraph
- Owner: otiai10
- License: mit
- Created: 2017-09-06T02:21:43.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-04-30T18:57:25.000Z (over 1 year ago)
- Last Synced: 2024-10-17T15:35:33.408Z (27 days ago)
- Topics: go, html, ogp, ogp-image, ogp-meta, ogp-tags
- Language: Go
- Homepage: https://pkg.go.dev/github.com/otiai10/opengraph
- Size: 86.9 KB
- Stars: 66
- Watchers: 4
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Open Graph Parser for Golang
Go implementation of https://ogp.me/
[![reference](https://pkg.go.dev/badge/github.com/otiai10/opengraph)](https://pkg.go.dev/github.com/otiai10/opengraph/v2)
[![Go](https://github.com/otiai10/opengraph/workflows/Go/badge.svg)](https://github.com/otiai10/opengraph/actions)
[![codecov](https://codecov.io/gh/otiai10/opengraph/branch/main/graph/badge.svg?token=D4mPKqi9fH)](https://codecov.io/gh/otiai10/opengraph)
[![Maintainability](https://api.codeclimate.com/v1/badges/d063131639023e9a8900/maintainability)](https://codeclimate.com/github/otiai10/opengraph/maintainability)
[![Go Report Card](https://goreportcard.com/badge/github.com/otiai10/opengraph)](https://goreportcard.com/report/github.com/otiai10/opengraph)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/otiai10/opengraph/blob/main/LICENSE)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fotiai10%2Fopengraph.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fotiai10%2Fopengraph?ref=badge_shield)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/otiai10/opengraph?sort=semver)](https://pkg.go.dev/github.com/otiai10/opengraph/v2)# Code Example
```go
package mainimport (
"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
```sh
% go get github.com/otiai10/opengraph/ogp
% ogp --help
% ogp -A otiai10.com
```Just for fun 😉
# Advanced usage
Set an option for fetching:
```go
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:
```go
f, _ := os.Open("my_test.html")
defer f.Close()
ogp := &opengraph.OpenGraph{}
err := ogp.Parse(f)
```or if you already have parsed `*html.Node`:
```go
err := ogp.Walk(node)
```Do you wanna make absolute URLs?:
```go
ogp.Image[0].URL // /logo.png
ogp.ToAbs()
ogp.Image[0].URL // https://ogp.me/logo.png
```# Issues
- https://github.com/otiai10/opengraph/issues