middlewares all now have the same signature
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -65,11 +65,12 @@ func (s *server) LoggingMiddleware() func(http.Handler) http.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// this is the HandleFunc wrapper type for a *specific route*, it doesn't go
|
||||
// on the mux.
|
||||
func (s *server) AuthMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
s.log.Info().Msg("AUTH: before request")
|
||||
next(w, r)
|
||||
func (s *server) AuthMiddleware() func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// FIXME you'll want to change this to do stuff.
|
||||
s.log.Info().Msg("AUTH: before request")
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,15 @@ import (
|
||||
func (s *server) routes() {
|
||||
s.router = mux.NewRouter()
|
||||
|
||||
authMiddleware := s.AuthMiddleware()
|
||||
|
||||
s.router.HandleFunc("/", s.handleIndex()).Methods("GET")
|
||||
s.router.HandleFunc("/login", s.AuthMiddleware(s.handleLogin())).Methods("GET")
|
||||
|
||||
// if you want to use a general purpose middleware (http.Handler
|
||||
// wrapper) on a specific HandleFunc route, you need to take the
|
||||
// .ServeHTTP of the http.Handler to get a HandleFunc, viz:
|
||||
s.router.HandleFunc("/login", authMiddleware(s.handleLogin()).ServeHTTP).Methods("GET")
|
||||
|
||||
s.router.HandleFunc("/.well-known/healthcheck.json", s.handleHealthCheck()).Methods("GET")
|
||||
|
||||
s.router.Use(s.LoggingMiddleware())
|
||||
|
||||
Reference in New Issue
Block a user