From 25f5fae505029d20a60cab0b88f43d5bf9bfdb21 Mon Sep 17 00:00:00 2001 From: Florian Walther Date: Mon, 9 Feb 2026 17:16:06 +0100 Subject: [PATCH] added env config COUNTER_FILE, DEBUG --- main.go | 16 ++++++++++++++++ misc/MoreUsage.md | 12 +++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 878e085..35a426a 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,21 @@ var ( mu sync.Mutex ) +func initConfig() { + // 1. Counter-Pfad auslesen + if envFile := os.Getenv("COUNTER_FILE"); envFile != "" { + counterFile = envFile + log.Printf("counterFile st to %s, by ENV\n", envFile) + } + + // 2. Debug-Modus auslesen (String zu Bool) + envDebug := strings.ToLower(os.Getenv("DEBUG")) + if envDebug == "true" || envDebug == "1" { + debug = true + log.Println("DEBUG-Modus ist aktiviert") + } +} + type responseWriter struct { http.ResponseWriter statusCode int @@ -214,6 +229,7 @@ func helpHandler(w http.ResponseWriter, r *http.Request) { } func main() { + initConfig() loadTemplates() mux := http.NewServeMux() diff --git a/misc/MoreUsage.md b/misc/MoreUsage.md index c0c55ac..7a006f9 100644 --- a/misc/MoreUsage.md +++ b/misc/MoreUsage.md @@ -25,11 +25,21 @@ for i in {1..10}; do echo $(curl -s https://passwd.scu.si/api/password); done you can build the app yourself like this: ``` -go build -o password-generator ./ +go build ./ ``` NOTE: If you build the app manually in go, like shown in this example, it will probably not run, since it misses a writeable `/data` directory. +You can set the counterFile by environment variable `COUNTER_FILE`, like this: +``` +COUNTER_FILE=./counter.txt ./Web-Password +``` +## debuging the app + +You can turn on debug mode via environment variable `DEBUG` +``` +DEBUG=true ./Web-Password +``` # build a docker container