package pkg import ( "net/http" ) func NewRouter(db *Db) http.Handler { router := http.NewServeMux() router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static")))) router.Handle("/login", LoginHandler(db)) router.Handle("/logout", LogoutHandler(db)) router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { user := getUser(r) if user.LoggedIn { renderTemplate(w, r, "index.html", nil) } else { http.Redirect(w, r, "/login", http.StatusSeeOther) } }) var handler http.Handler = router handler = Locale(handler) handler = CheckLogin(db, handler) handler = Recoverer(handler) handler = Logger(handler) return handler }