From f62f333e2906cc35aa00e4fc4d1c0958f61ab53e Mon Sep 17 00:00:00 2001
From: gjahn <gregor.jahn@bht-berlin.de>
Date: Mon, 27 Nov 2023 22:16:00 +0100
Subject: [PATCH] Set up routes can now return an error

This is to improve/funnel potentially fatal errors
---
 main.go                | 5 ++++-
 routing/routes.go      | 7 +++++--
 routing/routes_test.go | 2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go
index f9bbd9f..3beb4ae 100644
--- a/main.go
+++ b/main.go
@@ -38,7 +38,10 @@ func main() {
 
     var isHealthy = false
 
-    routing.SetRoutes( server, config, store, &isHealthy )
+    err = routing.SetRoutes( server, config, store, &isHealthy )
+    if err != nil {
+        log.Fatalf( "HTTP server failed to start: %v", err )
+    }
 
     go func(){
         err := server.Listen( fmt.Sprintf( "%s:%d", config.Host, config.Port ) )
diff --git a/routing/routes.go b/routing/routes.go
index 0455c76..a9504cd 100644
--- a/routing/routes.go
+++ b/routing/routes.go
@@ -18,11 +18,11 @@ import (
 )
 
 
-func SetRoutes( router *f.App, config *configuration.Config, store state.Store, healthiness *bool ) {
+func SetRoutes( router *f.App, config *configuration.Config, store state.Store, healthiness *bool ) error {
 
     indexHtmlTemplate, err := template.New( "index" ).Parse( indexHtml )
     if err != nil {
-        log.Fatal( err )
+        return err
     }
 
     if config.LogLevel == "debug" {
@@ -237,4 +237,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
     router.Use( func( c *f.Ctx ) error {
         return c.SendStatus( http.StatusTeapot )
     })
+
+
+    return nil
 }
diff --git a/routing/routes_test.go b/routing/routes_test.go
index 5c9bfd8..c13d9a3 100644
--- a/routing/routes_test.go
+++ b/routing/routes_test.go
@@ -32,7 +32,7 @@ func setup() ( *f.App, *configuration.Config, state.Store, *bool ){
     })
     store := state.NewEphemeralStore()
     var isHealthy = true
-    SetRoutes( server, config, store, &isHealthy )
+    _ = SetRoutes( server, config, store, &isHealthy )
 
     return server, config, store, &isHealthy
 }
-- 
GitLab