diff --git a/enum.go b/enum.go new file mode 100644 index 0000000..002c6f7 --- /dev/null +++ b/enum.go @@ -0,0 +1,7 @@ +package httpserver + +// These are constants to have an single point to look up static items +const ( + Accounts = "account" + Menus = "menu" +) diff --git a/http.go b/http.go index a497475..00992ba 100644 --- a/http.go +++ b/http.go @@ -64,9 +64,13 @@ func CreateServer(config *toml.Tree) *Server { router: gin.New(), authhf: &auth.AnonAccountHandler{}, } - server.Use(func(c *gin.Context) { - c.Set("account", server.authhf.Account(c)) - }) + mw := []gin.HandlerFunc{ + func(c *gin.Context) { + c.Set(Accounts, server.authhf.Account(c)) + c.Set(Menus, server.menus) + }, + } + server.Use(mw...) if err := config.Unmarshal(server.conf); err != nil { log.Error().Msg("Problem mapping config to Configstruct") } @@ -79,7 +83,7 @@ func CreateServer(config *toml.Tree) *Server { } server.router.NoRoute(gin.WrapH(http.NotFoundHandler())) gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { - log.Trace().Msgf("%-4s(%02d): %-20s %s", httpMethod, nuHandlers-1, absolutePath, handlerName) + log.Trace().Msgf("%-4s(%02d): %-20s %s", httpMethod, nuHandlers-len(mw), absolutePath, handlerName) } server.menus = []menus.Menu{} return server