Exemple #1
0
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
}
Exemple #2
0
func privateRoutesFactory(router *httpway.Router) {
	router.GET("/profile", private.Profile)
	router.GET("/logout", private.Logout)
}
Exemple #3
0
func publicRoutesFactory(router *httpway.Router) {
	router.GET("/", public.Index)
	router.GET("/login/:username", public.Login)
}