repositorypackage
1.0.6
Repository: https://github.com/payfazz/go-middleware.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
# README
go-middleware
Golang middleware collection
Middleware is value that have following type
func(http.HandlerFunc) http.HandlerFunc
In following example, testMiddleware
is a middleware that adding some header to the response
var handler http.HandlerFunc = ...
var someMiddleware func(next http.HandlerFunc) http.HanlderFunc = ...
testMiddleware := func(next http.HandlerFunc) http.HanlderFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("TestHeader", "test value")
next(w, r)
}
}
combinedHandler := someMiddleware(testMiddleware(handler))
Use httpchain package to chaining multiple middleware, so you can write
combinedHandler := httpchain.Chain(
someMiddleware,
testMiddleware,
handler,
)