aboutsummaryrefslogtreecommitdiff
path: root/internal/passwdmiddleware.go
blob: 8fa511ac06021bebbe021f046f79744b9a9861b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package internal

import "net/http"

func PasswordMiddleware(username, password string, next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		user, pass, ok := r.BasicAuth()
		if !ok || user != username || pass != password {
			http.Error(w, "Unauthorized", http.StatusUnauthorized)
			return
		}

		next.ServeHTTP(w, r)
	})
}