34 lines
663 B
Go
34 lines
663 B
Go
package router
|
|
|
|
import (
|
|
"lishwist/http/response"
|
|
"net/http"
|
|
|
|
"github.com/Teajey/sqlstore"
|
|
)
|
|
|
|
type VisibilityRouter struct {
|
|
Store *sqlstore.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["authorized"].(bool)
|
|
|
|
if authorized {
|
|
s.Private.ServeHTTP(w, r)
|
|
} else {
|
|
s.Public.ServeHTTP(w, r)
|
|
}
|
|
}
|
|
|
|
func New(store *sqlstore.Store) *VisibilityRouter {
|
|
return &VisibilityRouter{
|
|
Store: store,
|
|
Public: response.NewServeMux(store),
|
|
Private: response.NewServeMux(store),
|
|
}
|
|
}
|