/go-methods

Status code 405 like what?!?!?

Primary LanguageGoMIT LicenseMIT

go-methods

Build Status godoc

limit handler access to certain HTTP verbs

Package methods provides HTTP middleware for limiting access to a handler to certain HTTP methods.

Installation using go get

$ go get github.com/m90/go-methods

Usage

Wrap a handler using Allow(...string), allowing only the given methods:

var getOnlyHandler := Allow(http.MethodGet)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("Thanks for GETting!"))
}))

Wrap a handler using Disallow(...string), disallowing the given methods:

var noUpdateHandler := Disallow(http.MethodPut, http.MethodPatch)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("Thanks for not updating!"))
}))

License

MIT © Frederik Ring