1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor: middlewares and get rid of negroni

This commit is contained in:
Ferdinand Mütsch
2020-05-24 14:50:04 +02:00
parent 041a49ede4
commit a317dc6942
5 changed files with 53 additions and 44 deletions

View File

@@ -30,7 +30,13 @@ func NewAuthenticateMiddleware(config *models.Config, userService *services.User
}
}
func (m *AuthenticateMiddleware) Handle(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
func (m *AuthenticateMiddleware) Handler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m.ServeHTTP(w, r, h.ServeHTTP)
})
}
func (m *AuthenticateMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
for _, p := range m.whitelistPaths {
if strings.HasPrefix(r.URL.Path, p) || r.URL.Path == p {
next(w, r)