MCPcopy Index your code
hub / github.com/dreamsofcode-io/nethttp / EnsureAdmin

Function EnsureAdmin

middleware/generic.go:9–19  ·  view source on GitHub ↗
(next http.Handler)

Source from the content-addressed store, hash-verified

7)
8
9func EnsureAdmin(next http.Handler) http.Handler {
10 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
11 log.Println("Checking if user is admin")
12 if !strings.Contains(r.Header.Get("Authorization"), "Admin") {
13 w.WriteHeader(http.StatusUnauthorized)
14 w.Write([]byte(http.StatusText(http.StatusUnauthorized)))
15 return
16 }
17 next.ServeHTTP(w, r)
18 })
19}
20
21func LoadUser(next http.Handler) http.Handler {
22 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 1

WriteHeaderMethod · 0.80

Tested by

no test coverage detected