Drago is an idiomatic HTTP Middleware for Go.
go get github.com/nanoninja/drago
After installing Go and setting up your
GOPATH, create your first .go
file.
package main
import (
"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)
}
d := drago.New()
d.Use(Middleware1, Middleware2)
handler := d.Handler(http.NewServeMux())
a := drago.New(Middleware1, Middleware2)
b := drago.New(Middleware3, Middleware4)
a.Extend(b) // a == Middleware1, Middleware2, Middleware3, Middleware4
handler := a.Handler(http.NewServeMux())
d := drago.New(Middleware1, Middleware2)
handler := d.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprintf(rw, "Welcome!")
})
Here is a current list of Drago compatible middleware :
Middleware | Author | Description |
---|---|---|
Bulma | Vincent Letourneau | Basic authentication implementation for Go. |
Goshi | Vincent Letourneau | Goshi is an extension of http.ResponseWriter written in Go. |
Drago is licensed under the Creative Commons Attribution 3.0 License, and code is licensed under a BSD license.