Skip to content
/ googp Public

googp is an OGP (Open Graph protocol) parser library for Golang.

License

Notifications You must be signed in to change notification settings

soranoba/googp

Repository files navigation

googp

CircleCI Go Report Card PkgGoDev

googp is an OGP (Open Graph protocol) parser library for Golang.

Overviews

  • 💯 Fully compliant with the reference
  • 🔧 Highly customizable
    • Available your own structs
    • Available parsing your own OG Tags.
  • 🙌 Supports type conversion

Installation

To install it, run:

go get -u github.com/soranoba/googp

Usage

import (
    "fmt"
    "github.com/soranoba/googp"
)

type Music struct {
}

type CustomOGP struct {
    Title       string   `googp:"og:title"`
    Description string   `googp:"-"`        // ignored
    images      []string                    // private field (ignored)
    Videos      []string `googp:"og:video,og:video:url"`
    Musics      Music    `googp:"music"`    // object type
}

func main() {
    var ogp1 googp.OGP
    if err := googp.Fetch("https://soranoba.net", &ogp1); err != nil {
        return
    }
    fmt.Println(ogp1)

    var ogp2 CustomOGP
    if err := googp.Fetch("https://soranoba.net", &ogp2); err != nil {
        return
    }
    fmt.Println(ogp2)
}

Object Mappings

type OGP struct {
    Image struct {
        URL       string `googp:"og:image,og:image:url"`
        SecureURL string `googp:"og:image:secure_url"`
    } `googp:"og:image"`
}

You may collect in a struct by specifying the root tag.
In case of specifying og:image, googp collect values which property is og:image:*.

type OGP struct {
    Image []string `googp:"og:image"`
}

googp collects values which the same properties.

In googp, it same as Structured Properties.
You may define your own type yourself.

About

googp is an OGP (Open Graph protocol) parser library for Golang.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published