From c3a1564c4eb043a18c32f1e8d8ec1ed0a383a60f Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 9 Feb 2022 21:56:40 +0000 Subject: [PATCH] Extract LoadRoutes method --- http/http.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/http/http.go b/http/http.go index 745e60b..53870b4 100644 --- a/http/http.go +++ b/http/http.go @@ -4,7 +4,6 @@ import ( "io/fs" "net/http" "strings" - "time" "git.javil.eu/jacob1123/budgeteer" "git.javil.eu/jacob1123/budgeteer/bcrypt" @@ -25,11 +24,15 @@ const ( expiration = 72 ) -// Serve starts the HTTP Server +// Serve starts the http server func (h *Handler) Serve() { router := gin.Default() - router.FuncMap["now"] = time.Now + h.LoadRoutes(router) + router.Run(":1323") +} +// LoadRoutes initializes all the routes +func (h *Handler) LoadRoutes(router *gin.Engine) { static, err := fs.Sub(web.Static, "dist") if err != nil { panic("couldn't open static files") @@ -77,8 +80,6 @@ func (h *Handler) Serve() { transaction := authenticated.Group("/transaction") transaction.POST("/new", h.newTransaction) transaction.POST("/:transactionid", h.newTransaction) - - router.Run(":1323") } func enableCachingForStaticFiles() gin.HandlerFunc {