Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add env var support for static-dir and i18n-dir flags (#2807)

Alan Fullere703c37eb0af
diff --git a/cmd/main.go b/cmd/main.go
index 082303a2..784b5fc7 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -120,8 +120,17 @@ func init() {
initConfigFiles(ko.Strings("config"), ko)
// Load environment variables and merge into the loaded config.
+ // LISTMONK_foo__bar -> foo.bar (double underscore becomes dot for nested config)
+ // LISTMONK_static_dir -> static-dir (top-level keys with underscore become hyphen for CLI flags)
if err := ko.Load(env.Provider("LISTMONK_", ".", func(s string) string {
- return strings.Replace(strings.ToLower(strings.TrimPrefix(s, "LISTMONK_")), "__", ".", -1)
+ key := strings.ToLower(strings.TrimPrefix(s, "LISTMONK_"))
+ key = strings.Replace(key, "__", ".", -1)
+ // Only convert underscore to hyphen for top-level keys (CLI flags like static-dir, i18n-dir)
+ // Nested config keys (containing dots) keep underscores (e.g., db.ssl_mode)
+ if !strings.Contains(key, ".") {
+ key = strings.Replace(key, "_", "-", -1)
+ }
+ return key
}), nil); err != nil {
lo.Fatalf("error loading config from env: %v", err)
}