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()) router.Handle("/logout", LogoutHandler()) router.Handle("/profile", ProfileHandler()) router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { user := getUser(r) if user.LoggedIn { mustRenderAppTemplate(w, r, "dashboard.html", nil) } else { http.Redirect(w, r, "/login", http.StatusSeeOther) } }) var handler http.Handler = router handler = Locale(db, handler) handler = CheckLogin(db, handler) handler = Recoverer(handler) handler = Logger(handler) return handler }