Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acoshift/methodmux
Method Multiplexer for http.ServeMux
https://github.com/acoshift/methodmux
Last synced: about 1 month ago
JSON representation
Method Multiplexer for http.ServeMux
- Host: GitHub
- URL: https://github.com/acoshift/methodmux
- Owner: acoshift
- License: mit
- Created: 2018-03-14T06:18:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-14T16:54:20.000Z (almost 7 years ago)
- Last Synced: 2024-05-01T13:24:31.917Z (8 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# methodmux
[![Build Status](https://travis-ci.org/acoshift/methodmux.svg?branch=master)](https://travis-ci.org/acoshift/methodmux)
[![Coverage Status](https://coveralls.io/repos/github/acoshift/methodmux/badge.svg?branch=master)](https://coveralls.io/github/acoshift/methodmux?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/acoshift/methodmux)](https://goreportcard.com/report/github.com/acoshift/methodmux)
[![GoDoc](https://godoc.org/github.com/acoshift/methodmux?status.svg)](https://godoc.org/github.com/acoshift/methodmux)Method Multiplexer for http.ServeMux
## Example
```go
package mainimport (
"io"
"net/http""github.com/acoshift/methodmux"
)func main() {
mux := http.NewServeMux()
mux.Handle("/", methodmux.Get(http.HandlerFunc(index)))
mux.Handle("/about", methodmux.Mux{
http.MethodGet: http.HandlerFunc(aboutGet),
http.MethodPost: http.HandlerFunc(aboutPost),
"": http.HandlerFunc(aboutOther),
})
http.ListenAndServe(":8080", mux)
}func index(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello, Method Mux!")
}func aboutGet(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "About Get")
}func aboutPost(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "About Post")
}func aboutOther(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "About does not support method "+r.Method)
}
```