3 ms·
Golang MiddleWare chaining
- anonfunction 12y agoSuperb timing as I'm just now implementing some web services in Go and using http.Handler compatible middlewares. As an alternative there is also Alice[1] but I don't like it's implementation style. Coming from JS and using connect / express what I'd really like is something more like this: func helloWorld() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello world!")) }) } func main() { // Wrap the app in Middleware app := SomeMiddlewareLibrary(helloWorld) // Run the middleware in this order app.Use(app.Logger("HELLO-WORLD")) app.Use(app.CORS("*")) app.Use(app.Delay("1s")) // Give the app up to be served http.ListenAndServe(":8080", app) } [1] https://github.com/justinas/alice https://github.com/justinas/alice
- squiidz 12y agoIf someone have some idea of improvements, please let me know ! :)
- deleted 12y ago[deleted]