Categorygithub.com/soranoba/googp
modulepackage
1.0.3
Repository: https://github.com/soranoba/googp.git
Documentation: pkg.go.dev

# README

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

Structured Properties

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:*.

Arrays

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

googp collects values which the same properties.

Object Types

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

# Functions

Fetch the content from the URL and parse OGP information.
NewParser create a `Parser`.
Parse OGP information.

# Variables

ErrUnsupportedPage is an unsupported page errror.

# Structs

Audio is a model that structure contents of og:audio.
BadStatusCodeError is an error returned when the status code is not 200 in Fetch.
Image is a model that structure contents of og:image.
Meta is a model that structure contents of meta tag in html.
OGP is a model that have Basic Metadata and Optional Metadata defined in the reference.
Parser is an OGP parser.
ParserOpts is an option of Parser.
Video is a model that structure contents of og:video.