From df2b0fb1ac616b53c071b91a0b1f22f1f8144b84 Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 2 Oct 2020 22:45:09 -0700 Subject: [PATCH] format comments better --- httpserver/routes.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/httpserver/routes.go b/httpserver/routes.go index e903835..5ed8121 100644 --- a/httpserver/routes.go +++ b/httpserver/routes.go @@ -9,25 +9,30 @@ import ( ) func (s *server) routes() { + s.router = chi.NewRouter() - // the mux .Use() takes a http.Handler wrapper func, like - // most things that deal with "middlewares" like alice et c, and - // will call ServeHTTP on it. These middlewares applied by the mux - // (you can .Use() more than one) will be applied to every request - // into the service. + // the mux .Use() takes a http.Handler wrapper func, like most + // things that deal with "middlewares" like alice et c, and will + // call ServeHTTP on it. These middlewares applied by the mux (you + // can .Use() more than one) will be applied to every request into + // the service. s.router.Use(middleware.RequestID) s.router.Use(s.LoggingMiddleware()) - // timeout for request context + + // timeout for request context: your handlers must finish within + // this window: + // CHANGEME to suit your needs, or pull from config. s.router.Use(middleware.Timeout(60 * time.Second)) - // this adds a sentry reporting middleware if and only if - // sentry is enabled via setting of SENTRY_DSN in env. - // this was at the bottom, but chi requires *all* middlewares - // applied before any routes are, so now it's up here. - // unfortunately this cannot coexist with the normal chi Recoverer - // handler which prints a nice stack trace to the console + // this adds a sentry reporting middleware if and only if sentry is + // enabled via setting of SENTRY_DSN in env. this was at the + // bottom, but chi requires *all* middlewares applied before any + // routes are, so now it's up here. unfortunately this cannot + // coexist with the normal chi Recoverer handler which prints a nice + // colorful stack trace to the console + if s.sentryEnabled { // Options docs at // https://docs.sentry.io/platforms/go/guides/http/ @@ -45,11 +50,13 @@ func (s *server) routes() { // ROUTES // complete docs: https://github.com/go-chi/chi //////////////////////////////////////////////////////////////////////// + s.router.Get("/", s.handleIndex()) // if you want to use a general purpose middleware (http.Handler // wrapper) on a specific HandleFunc route, you need to take the // .ServeHTTP of the http.Handler to get its HandleFunc, viz: + authMiddleware := s.AuthMiddleware() s.router.Get( "/login", @@ -63,6 +70,7 @@ func (s *server) routes() { // route that panics for testing // CHANGEME remove this + s.router.Get( "/panic", s.handlePanic(),