udemy-go-web-2/cmd/api/middleware.go

15 lines
295 B
Go
Raw Normal View History

package main
import "net/http"
func (app *application) Auth(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := app.authenticateToken(r)
if err != nil {
app.invalidCredentials(w)
return
}
next.ServeHTTP(w, r)
})
}