Categorygithub.com/ammit/go-metaparser
modulepackage
1.0.0
Repository: https://github.com/ammit/go-metaparser.git
Documentation: pkg.go.dev

# README

Build Status Go Report Card

go-metaparser

Lightweight metadata parser written in Go

With go-metaparser, you can easily extract structured meta-data from HTML. The purpose of this library is to be able to obtain all types of metadata from the web page.

Currently, it supports Open Graph, Twitter Card Metadata and some general metadata that doesn't belong to a particular type, for example - title, description etc.

Installation

Install the package with:

go get github.com/ammit/go-metaparser

Import it with:

import "github.com/ammit/go-metaparser"

and use parser as the package name inside the code.

Usage example

Please check the example folder for details.

package main

import (
	"fmt"

	parser "github.com/ammit/go-metaparser"
)

const (
	url = "http://ogp.me"
)

func main() {
	p := parser.New()
	b, err := p.FetchHTML(url)
	if err != nil {
		fmt.Printf("Could not fetch html from given url: %v \n", url)
	}
	defer b.Close()

	err = p.ParseHTML(b)

	fmt.Printf("The parsed title is: %v \n", p.Title)
}

Performance

You can run the benchmarks yourself, but here's the output on my machine:

    BenchmarkParser-12         19024             62147 ns/op            9858 B/op        261 allocs/op

Contributing

  1. Fork it (https://github.com/ammit/go-metaparser/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request :)

# Functions

New ...

# Structs

Article
Article type in Open Graph.
Audio type in Open Graph.
Book type in Open Graph.
Favicon found in the head.
Image type in Open Graph.
Music type in Open Graph.
No description provided by the author
Parser ...
Profile type in Open Graph.
No description provided by the author
Twitter type in Open Graph.
Video type in Open Graph.