15 lines
311 B
Go
15 lines
311 B
Go
|
|
package auth
|
||
|
|
|
||
|
|
import "net/http"
|
||
|
|
|
||
|
|
func AdminRequiredMiddleware(next http.Handler) http.Handler {
|
||
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
ctx := r.Context()
|
||
|
|
if !IsAdmin(ctx) {
|
||
|
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
next.ServeHTTP(w, r)
|
||
|
|
})
|
||
|
|
}
|