2021-07-27 10:51:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/justinas/alice"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a *goBlog) isPrivate() bool {
|
2022-02-12 21:29:45 +00:00
|
|
|
return a.cfg.PrivateMode != nil && a.cfg.PrivateMode.Enabled
|
2021-07-27 10:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *goBlog) privateModeHandler(next http.Handler) http.Handler {
|
2022-02-18 15:35:53 +00:00
|
|
|
private := alice.New(a.authMiddleware).Then(next)
|
2021-07-27 10:51:08 +00:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if a.isPrivate() {
|
2022-02-18 15:35:53 +00:00
|
|
|
private.ServeHTTP(w, r)
|
|
|
|
return
|
2021-07-27 10:51:08 +00:00
|
|
|
}
|
2022-02-18 15:35:53 +00:00
|
|
|
next.ServeHTTP(w, r)
|
2021-07-27 10:51:08 +00:00
|
|
|
})
|
|
|
|
}
|