1
mirror of https://github.com/jlelse/GoBlog synced 2024-06-01 11:54:27 +00:00
GoBlog/privateMode.go

23 lines
453 B
Go

package main
import (
"net/http"
"github.com/justinas/alice"
)
func (a *goBlog) isPrivate() bool {
return a.cfg.PrivateMode != nil && a.cfg.PrivateMode.Enabled
}
func (a *goBlog) privateModeHandler(next http.Handler) http.Handler {
private := alice.New(a.authMiddleware).Then(next)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if a.isPrivate() {
private.ServeHTTP(w, r)
return
}
next.ServeHTTP(w, r)
})
}