func MiddlewaresFactory(router *httpway.Router) (routes map[string]*httpway.Router) { routes = make(map[string]*httpway.Router) routes["public"] = router routes["private"] = router.Middleware(func(w http.ResponseWriter, r *http.Request) { ctx := httpway.GetContext(r) if !ctx.Session().IsAuth() { w.WriteHeader(http.StatusUnauthorized) fmt.Fprint(w, "Not authenticated") return } ctx.Next(w, r) }) return }
func privateRoutesFactory(router *httpway.Router) { router.GET("/profile", private.Profile) router.GET("/logout", private.Logout) }
func publicRoutesFactory(router *httpway.Router) { router.GET("/", public.Index) router.GET("/login/:username", public.Login) }