35 lines
650 B
Go
35 lines
650 B
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"lishwist/http/response"
|
|
"lishwist/http/session"
|
|
)
|
|
|
|
type VisibilityRouter struct {
|
|
store *session.Store
|
|
Public *response.ServeMux
|
|
Private *response.ServeMux
|
|
}
|
|
|
|
func (s *VisibilityRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
session, _ := s.store.Get(r, "lishwist_user")
|
|
_, authorized := session.Values["sessionKey"]
|
|
|
|
|
|
if authorized {
|
|
s.Private.ServeHTTP(w, r)
|
|
} else {
|
|
s.Public.ServeHTTP(w, r)
|
|
}
|
|
}
|
|
|
|
func New(store *session.Store) *VisibilityRouter {
|
|
return &VisibilityRouter{
|
|
store: store,
|
|
Public: response.NewServeMux(store),
|
|
Private: response.NewServeMux(store),
|
|
}
|
|
}
|