methods

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2018 License: MIT Imports: 1 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Allow = makeMiddleware(contains)

Allow will only pass through requests to the given handler if the request's method is contained in the given list of HTTP methods

View Source
var Disallow = makeMiddleware(func(needle string, haystack []string) bool {
	return !contains(needle, haystack)
})

Disallow will not pass through requests to the given handler if the request's method is contained in the given list of HTTP methods

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL