https://github.com/nanoninja/drago
Drago is an idiomatic HTTP Middleware for Go
https://github.com/nanoninja/drago
golang handler http middleware
Last synced: 6 months ago
JSON representation
Drago is an idiomatic HTTP Middleware for Go
- Host: GitHub
- URL: https://github.com/nanoninja/drago
- Owner: nanoninja
- License: bsd-3-clause
- Created: 2016-08-14T14:24:28.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-23T06:45:28.000Z (about 9 years ago)
- Last Synced: 2025-02-14T15:36:06.656Z (8 months ago)
- Topics: golang, handler, http, middleware
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Drago
Drago is an idiomatic HTTP Middleware for Go.
[](https://github.com/nanoninja/drago/blob/master/LICENSE) [](https://godoc.org/github.com/nanoninja/drago)
[](https://travis-ci.org/nanoninja/drago)
[](https://coveralls.io/github/nanoninja/drago?branch=master)
[](https://goreportcard.com/report/github.com/nanoninja/drago) [](https://codebeat.co/projects/github-com-nanoninja-drago)## Installation
go get github.com/nanoninja/drago
## Getting Started
After installing Go and setting up your
[GOPATH](http://golang.org/doc/code.html#GOPATH), create your first `.go` file.``` go
package mainimport (
"fmt"
"net/http""github.com/nanoninja/drago"
)func DemoMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
fmt.Println("Demo Middleware Before")
next.ServeHTTP(rw, r)
fmt.Println("Demo Middleware After")
})
}func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprintf(rw, "Welcome to the home page!")
})handler := drago.New(DemoMiddleware).Handler(mux)
http.ListenAndServe(":3000", handler)
}
```## Usage examples
### Use
``` go
d := drago.New()d.Use(Middleware1, Middleware2)
handler := d.Handler(http.NewServeMux())
```### Extend
``` go
a := drago.New(Middleware1, Middleware2)
b := drago.New(Middleware3, Middleware4)a.Extend(b) // a == Middleware1, Middleware2, Middleware3, Middleware4
handler := a.Handler(http.NewServeMux())
```### HandlerFunc
``` go
d := drago.New(Middleware1, Middleware2)handler := d.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprintf(rw, "Welcome!")
})
```## Third Party Middleware
Here is a current list of Drago compatible middleware :
| Middleware | Author | Description |
| -----------|--------|-------------|
| [Bulma](https://github.com/nanoninja/bulma) | [Vincent Letourneau](https://github.com/nanoninja) | Basic authentication implementation for Go. |
| [Goshi](https://github.com/nanoninja/goshi) | [Vincent Letourneau](https://github.com/nanoninja) | Goshi is an extension of http.ResponseWriter written in Go. |## License
Drago is licensed under the Creative Commons Attribution 3.0 License, and code is licensed under a [BSD license](https://github.com/nanoninja/drago/blob/master/LICENSE).