From a7cb7e3ef11f14017ecfd900205fde1b1b38f386 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Sun, 18 Dec 2022 08:59:48 +0100 Subject: [PATCH] Pass system to template --- main.go | 20 ++++++++++++++------ system/system.go | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 056c018..77b5b92 100644 --- a/main.go +++ b/main.go @@ -41,23 +41,31 @@ func main() { defer g.logger.Sync() g.setupEchoLogging() - w := weather.NewWeatherService(g.logger) - b := bookmarks.NewBookmarkService(g.logger) - if g.config.LiveSystem { - system.NewSystemService(g.logger) - } - g.router.Use(middleware.Recover()) g.router.Use(middleware.GzipWithConfig(middleware.GzipConfig{Level: 5})) g.router.Pre(middleware.RemoveTrailingSlash()) + w := weather.NewWeatherService(g.logger) + b := bookmarks.NewBookmarkService(g.logger) + var s *system.System + if g.config.LiveSystem { + s = system.NewSystemService(g.logger) + } + g.router.GET("/", func(c echo.Context) error { return c.Render(http.StatusOK, "index.gohtml", map[string]interface{}{ "Title": g.config.Title, "Weather": w.CurrentWeather, "Bookmarks": b.Categories, + "System": s, }) }) g.router.Static("/static", "static") + g.router.Static("/storage/icons", "storage/icons") + + g.router.GET("/robots.txt", func(c echo.Context) error { + return c.String(http.StatusOK, "User-agent: *\nDisallow: /") + }) + g.router.Logger.Fatal(g.router.Start(fmt.Sprintf(":%d", g.config.Port))) } diff --git a/system/system.go b/system/system.go index f3efd8d..056cbaf 100644 --- a/system/system.go +++ b/system/system.go @@ -5,9 +5,10 @@ import ( "time" ) -func NewSystemService(logging *zap.SugaredLogger) { +func NewSystemService(logging *zap.SugaredLogger) *System { s := System{log: logging} s.Initialize() + return &s } func (s *System) UpdateLiveInformation() {