limit handler access to certain HTTP verbs
Package methods
provides HTTP middleware for limiting access to a handler to certain HTTP methods.
$ go get github.com/m90/go-methods
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!"))
}))
MIT © Frederik Ring