https://github.com/m90/go-methods
Status code 405 like what?!?!?
https://github.com/m90/go-methods
Last synced: about 2 months ago
JSON representation
Status code 405 like what?!?!?
- Host: GitHub
- URL: https://github.com/m90/go-methods
- Owner: m90
- License: mit
- Created: 2017-08-25T18:11:11.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-22T08:46:23.000Z (about 6 years ago)
- Last Synced: 2025-04-02T22:40:28.795Z (2 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-methods
[](https://travis-ci.org/m90/go-methods)
[](http://godoc.org/github.com/m90/go-methods)> 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
```sh
$ go get github.com/m90/go-methods
```### Usage
Wrap a handler using `Allow(...string)`, allowing only the given methods:
```go
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:
```go
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](http://www.frederikring.com)