From b3ecabccd124956f0dcc367abcb61fb07170bea4 Mon Sep 17 00:00:00 2001
From: gjahn <gregor.jahn@bht-berlin.de>
Date: Thu, 14 Dec 2023 01:52:33 +0100
Subject: [PATCH] Allow setting font color of landing page via environment
 variable

---
 configuration/config.go | 20 +++++++++++++++++++-
 routing/routes.go       |  2 +-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/configuration/config.go b/configuration/config.go
index 2286c4b..688d37a 100644
--- a/configuration/config.go
+++ b/configuration/config.go
@@ -4,6 +4,7 @@ import (
     "errors"
     "fmt"
     "os"
+    "unicode"
     fp "path/filepath"
 
     configParser "github.com/caarlos0/env/v9"
@@ -18,6 +19,8 @@ var version string = "n/a"
 type Config struct {
     Version     string
 
+    FontColor   string `env:"FONT_COLOR"  envDefault:""`
+
     LogLevel    string `env:"LOG_LEVE"  envDefault:"error"`
 
     Environment     string `env:"ENV_NAME"  envDefault:"development"`
@@ -65,7 +68,6 @@ func New() ( *Config, error ){
         )
     }
 
-
     if len( cfg.DatabaseHost ) >= 1 && len( cfg.DatabasePassword ) >= 2 {
         if ! fp.IsLocal( cfg.DatabasePassword ) && ! fp.IsAbs( cfg.DatabasePassword ) {
             return nil, errors.New(
@@ -85,6 +87,22 @@ func New() ( *Config, error ){
         }
     }
 
+    if len( cfg.FontColor ) >= 1 {
+        if len( cfg.FontColor ) >= 21 {
+            return nil, errors.New(
+                fmt.Sprintln( "Font color too long" ),
+            )
+        }
+
+        for _, r := range cfg.FontColor {
+            if ! unicode.IsLetter( r ) {
+                return nil, errors.New(
+                    fmt.Sprintln( "Invalid character in font color" ),
+                )
+            }
+        }
+    }
+
 
     return &cfg, nil
 }
diff --git a/routing/routes.go b/routing/routes.go
index b787c8d..183609f 100644
--- a/routing/routes.go
+++ b/routing/routes.go
@@ -48,7 +48,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
 
         data := indexHtmlData{
             Version: config.Version,
-            Color: "",
+            Color: config.FontColor,
         }
 
         buffer := &bytes.Buffer{}
-- 
GitLab