mirror of
https://github.com/jlelse/GoBlog
synced 2024-06-29 11:27:34 +00:00
23 lines
453 B
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)
|
|
})
|
|
}
|