39 lines
714 B
Go
39 lines
714 B
Go
package mux
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"lishwist/http/handler"
|
|
"lishwist/http/session"
|
|
)
|
|
|
|
type Serve struct {
|
|
store *session.Store
|
|
Public *Private
|
|
Private *Private
|
|
}
|
|
|
|
func (s *Serve) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
session, _ := s.store.Get(r, "lishwist_user")
|
|
_, inSession := session.Values["sessionKey"]
|
|
|
|
if inSession {
|
|
s.Private.ServeHTTP(w, r)
|
|
} else {
|
|
s.Public.ServeHTTP(w, r)
|
|
}
|
|
}
|
|
|
|
func New(store *session.Store) *Serve {
|
|
return &Serve{
|
|
store: store,
|
|
Public: newPrivate(store),
|
|
Private: newPrivate(store),
|
|
}
|
|
}
|
|
|
|
func (r *Serve) HandleFunc(pattern string, handler handler.PublicFunc) {
|
|
r.Public.HandleFunc(pattern, handler)
|
|
r.Private.HandleFunc(pattern, handler)
|
|
}
|