18 lines
395 B
Go
18 lines
395 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"git.cryptic.systems/volker.raschek/prometheus-fail2ban-exporter/auth"
|
||
|
)
|
||
|
|
||
|
func AuthMiddleware(handlerFunc http.HandlerFunc, authProvider auth.AuthProvider) http.HandlerFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
if authProvider.IsAllowed(r) {
|
||
|
handlerFunc.ServeHTTP(w, r)
|
||
|
} else {
|
||
|
w.WriteHeader(http.StatusUnauthorized)
|
||
|
}
|
||
|
}
|
||
|
}
|