Skip to content
Snippets Groups Projects
user avatar
Will McCutchen authored
This adds a new /hostname endpoint as originally proposed in #66. In
this implementation, it exposes a dummy hostname by default, and only
exposes the real hostname (via `os.Hostname()`) if the
`-use-real-hostname` flag is given on the command line.
0defb3ce
History

HTTP Negotiation

Installation

go get gitlab.schukai.com/oss/libraries/go/application/http-negotiation

Note: This library uses Go Modules to manage dependencies.

What do this library?

This library provides a simple way to negotiate the content type of HTTP request.

It supports:

Usage

package main

import (
	"net/http"
	"gitlab.schukai.com/oss/libraries/go/application/http-negotiation"
)

func handleRequest(w http.ResponseWriter, r *http.Request) {
	n := negotiation.New(r.Header)

	if n.Type("application/json") == "application/json" {
		w.Header().Set("Content-Type", "application/json")
		w.Write([]byte(`{"message": "Hello World!"}`))
		return
	}

}

Contributing

Merge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

AGPL-3.0