Skip to content

Svjard/goaccepts

Repository files navigation

GoAccepts

Codacy Badge Go Report Card Build Status codecov DeepSource

Utility library that can parse the Accept* header to pull out encodings/languages/charsets/mimetypes for use by an API.

Usage

import "github.com/Svjard/goaccepts"

// Header sent in request with "en-US, it;q=0.6"
...
goaccepts.Languages(res.headers["Accept-Language"])

// will return []string{"en-US","it"}

Development

Each header type is seperated into its own file and parser.

Accept - media-type.go
Accept-Encoding - encoding.go
Accept-Charset - charset.go
Accept-Language - language.go

RFC Reference: https://tools.ietf.org/html/rfc2616

Each module has two specific functions, the first returns a raw string array representation of the accepted entities in order of weight. The second returns an array of structures which provides a specific breakdown and detail about each parsed entity.

Testing

To run the test suite run the following command:

go test -v ./...

To run the code coverage report run the following command:

./go.test.sh

About

Utility library to parse out Accepts headers

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published