Browse Source

Pass system to template

Florian Hoss 2 years ago
parent
commit
a7cb7e3ef1
2 changed files with 15 additions and 6 deletions
  1. 13 5
      main.go
  2. 2 1
      system/system.go

+ 13 - 5
main.go

@@ -41,23 +41,31 @@ func main() {
 	defer g.logger.Sync()
 	g.setupEchoLogging()
 
+	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 {
-		system.NewSystemService(g.logger)
+		s = system.NewSystemService(g.logger)
 	}
 
-	g.router.Use(middleware.Recover())
-	g.router.Use(middleware.GzipWithConfig(middleware.GzipConfig{Level: 5}))
-	g.router.Pre(middleware.RemoveTrailingSlash())
-
 	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)))
 }

+ 2 - 1
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() {