17 lines
415 B
Go
17 lines
415 B
Go
package auth
|
|
|
|
import "net/http"
|
|
|
|
func Require(secret string) func(http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
username := getSession(r, secret)
|
|
if username == "" {
|
|
http.Redirect(w, r, basePath+"/mcu-login", http.StatusSeeOther)
|
|
return
|
|
}
|
|
next.ServeHTTP(w, setContext(r, username))
|
|
})
|
|
}
|
|
}
|