An open API service indexing awesome lists of open source software.

https://github.com/sanae10001/go-simple-middleware

Simple go http middleware
https://github.com/sanae10001/go-simple-middleware

body-limit go go-middleware jwt negroni negroni-middleware

Last synced: 6 months ago
JSON representation

Simple go http middleware

Awesome Lists containing this project

README

          

# negroni-middlewares
Simple go http middleware

Support [negroni](https://github.com/urfave/negroni) and standard http library

- [x] Basic auth
- [x] Body limit
- [x] Request id
- [x] JWT

#### Example

*jwt*:

``` go
func main() {
h := func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
}
j := jwt.New(jwt.Config{SigningKey: []byte("asecretsigningstring")})

mux := http.NewServeMux()
mux.Handle("/", j.Handler(http.HandlerFunc(h)))

http.ListenAndServe(":8080", mux)
}
```

*jwt for negroni*

```go
func main() {
h := func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
}
j := jwt.New(jwt.Config{SigningKey: []byte("asecretsigningstring")})

mux := http.NewServeMux()
mux.HandleFunc("/", h)

n := negroni.New()
n.UseFunc(j.HandlerWithNext)
n.UseHandler(mux)

http.ListenAndServe(":8080", n)
}
```