package router import ( "lishwist/rsvp" "net/http" "github.com/Teajey/sqlstore" ) type VisibilityRouter struct { Store *sqlstore.Store Public *rsvp.ServeMux Private *rsvp.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: rsvp.NewServeMux(store), Private: rsvp.NewServeMux(store), } }