Skip to content

Instantly share code, notes, and snippets.

@Daniel1984
Created April 25, 2020 14:39
Show Gist options
  • Save Daniel1984/8d55ec19f569e36c702dee90094d1f4a to your computer and use it in GitHub Desktop.
Save Daniel1984/8d55ec19f569e36c702dee90094d1f4a to your computer and use it in GitHub Desktop.
// pkg/middleware/middleware.go
package middleware
import (
"github.com/julienschmidt/httprouter"
)
type Middleware func(httprouter.Handle) httprouter.Handle
func Chain(f httprouter.Handle, m ...Middleware) httprouter.Handle {
if len(m) == 0 {
return f
}
return m[0](Chain(f, m[1:]...))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment