Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kevinpollet/nego
Go package providing an implementation of HTTP Content Negotiation compliant with RFC 7231
https://github.com/kevinpollet/nego
content-charset content-encoding content-language content-negotiation content-type go golang http negotiate rfc7231
Last synced: about 1 month ago
JSON representation
Go package providing an implementation of HTTP Content Negotiation compliant with RFC 7231
- Host: GitHub
- URL: https://github.com/kevinpollet/nego
- Owner: kevinpollet
- License: mit
- Created: 2020-03-10T12:27:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-10T16:09:28.000Z (about 3 years ago)
- Last Synced: 2024-06-19T17:51:04.908Z (5 months ago)
- Topics: content-charset, content-encoding, content-language, content-negotiation, content-type, go, golang, http, negotiate, rfc7231
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# nego
[![Build Status](https://github.com/kevinpollet/nego/workflows/build/badge.svg)](https://github.com/kevinpollet/nego/actions)
[![GoDoc](https://godoc.org/github.com/kevinpollet/nego?status.svg)](https://pkg.go.dev/github.com/kevinpollet/nego)
[![Go Report Card](https://goreportcard.com/badge/github.com/kevinpollet/nego?burst=)](https://goreportcard.com/report/github.com/kevinpollet/nego)Go package providing an implementation of [HTTP Content Negotiation](https://en.wikipedia.org/wiki/Content_negotiation) compliant with [RFC 7231](https://tools.ietf.org/html/rfc7231#section-5.3).
As defined in [RFC 7231](https://tools.ietf.org/html/rfc7231#section-5.3) the following request headers are sent by a user agent to engage in a proactive negotiation of the response content: `Accept`, `Accept-Charset`, `Accept-Language` and `Accept-Encoding`.
This package provides convenient functions to negotiate the best and acceptable response content `type`, `charset`, `language` and `encoding`.## Installation
Install using `go get github.com/kevinpollet/nego`.
## Usage
```go
package mainimport (
"log"
"net/http"
"github.com/kevinpollet/nego"
)func main() {
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
contentCharset := nego.NegotiateContentCharset(req, "utf-8")
contentEncoding := nego.NegotiateContentEncoding(req, "gzip", "deflate")
contentLanguage := nego.NegotiateContentLanguage(req, "fr", "en")
contentType := nego.NegotiateContentType(req, "text/html", "text/plain")
...
})
}
```## Contributing
Contributions are welcome!
Want to file a bug, request a feature or contribute some code?
1. Check out the [Code of Conduct](./CODE_OF_CONDUCT.md).
2. Check for an existing [issue](https://github.com/kevinpollet/nego/issues) corresponding to your bug or feature request.
3. Open an issue to describe your bug or feature request.## License
[MIT](./LICENSE.md)