(username, password string)
| 3 | import "net/http" |
| 4 | |
| 5 | func BasicAuthMW(username, password string) func(http.Handler) http.Handler { |
| 6 | return func(next http.Handler) http.Handler { |
| 7 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 8 | if username != "" || password != "" { |
| 9 | authUser, authPass, ok := r.BasicAuth() |
| 10 | if !ok || username != authUser || password != authPass { |
| 11 | w.WriteHeader(http.StatusUnauthorized) |
| 12 | return |
| 13 | } |
| 14 | } |
| 15 | next.ServeHTTP(w, r) |
| 16 | }) |
| 17 | } |
| 18 | } |
no outgoing calls