1
0
Fork 0

The menus can now be accessed from the handlers

Dieser Commit ist enthalten in:
Sebastian Tobie 2021-01-20 00:12:54 +01:00
Ursprung a1b11a6adb
Commit 37e8ac835e
2 geänderte Dateien mit 15 neuen und 4 gelöschten Zeilen

7
enum.go Normale Datei
Datei anzeigen

@ -0,0 +1,7 @@
package httpserver
// These are constants to have an single point to look up static items
const (
Accounts = "account"
Menus = "menu"
)

12
http.go
Datei anzeigen

@ -64,9 +64,13 @@ func CreateServer(config *toml.Tree) *Server {
router: gin.New(), router: gin.New(),
authhf: &auth.AnonAccountHandler{}, authhf: &auth.AnonAccountHandler{},
} }
server.Use(func(c *gin.Context) { mw := []gin.HandlerFunc{
c.Set("account", server.authhf.Account(c)) 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 { if err := config.Unmarshal(server.conf); err != nil {
log.Error().Msg("Problem mapping config to Configstruct") 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())) server.router.NoRoute(gin.WrapH(http.NotFoundHandler()))
gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { 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{} server.menus = []menus.Menu{}
return server return server