18 lines
389 B
Go
18 lines
389 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func EnsureAdmin(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if !strings.Contains(r.Header.Get("Authorization"), "Admin") {
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
w.Write([]byte(http.StatusText(http.StatusUnauthorized)))
|
|
return
|
|
}
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|