From 37b27ec3e0a9b4f2c0c738fb3c511160cf020365 Mon Sep 17 00:00:00 2001 From: Kevin Kandlbinder Date: Tue, 7 Mar 2023 15:19:55 +0100 Subject: [PATCH] Add configuration via environment --- cmd/root.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 29d72d3..8ef3d65 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,6 +4,7 @@ import ( "github.com/Unkn0wnCat/calapi/internal/logger" "github.com/spf13/viper" "os" + "strings" "github.com/spf13/cobra" ) @@ -25,7 +26,10 @@ func Execute() { } func init() { - viper.SetDefault("development", true) + viper.SetEnvPrefix("calapi") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "__")) + + viper.SetDefault("development", false) viper.SetDefault("data_directory", "./data") viper.SetDefault("auth.type", "GHOST") viper.SetDefault("auth.secret", "hunter2") @@ -33,5 +37,7 @@ func init() { viper.SetDefault("auth.ghost.base_url", "https://content.hhga.1in9.net/ghost") viper.SetDefault("auth.ghost.limit_to_roles", nil) + viper.AutomaticEnv() + logger.StartLogger() }