@@ -7,9 +7,10 @@ import (
77 "strconv"
88 "strings"
99
10+ "github.com/codeshelldev/gotl/pkg/configutils"
11+ log "github.com/codeshelldev/gotl/pkg/logger"
12+ "github.com/codeshelldev/gotl/pkg/stringutils"
1013 "github.com/codeshelldev/secured-signal-api/internals/config/structure"
11- "github.com/codeshelldev/secured-signal-api/utils/configutils"
12- log "github.com/codeshelldev/secured-signal-api/utils/logger"
1314
1415 "github.com/knadh/koanf/parsers/yaml"
1516)
@@ -41,7 +42,7 @@ func Load() {
4142
4243 LoadTokens ()
4344
44- userConf .LoadEnv ()
45+ userConf .LoadEnv (normalizeEnv )
4546
4647 NormalizeConfig (defaultsConf )
4748 NormalizeConfig (userConf )
@@ -110,18 +111,19 @@ func Normalize(config *configutils.Config, path string, structure any) {
110111 // Load temporary config back into paths
111112 config .Layer .Delete (path )
112113
113- config .Load (tmpConf .Layer .Get ( "" ).( map [ string ] any ), path )
114+ config .Load (tmpConf .Layer .Raw ( ), path )
114115}
115116
116117func InitReload () {
117- reload := func () {
118+ reload := func (path string ) {
119+ log .Debug (path , " changed, reloading..." )
118120 Load ()
119121 Log ()
120122 }
121123
122- defaultsConf .OnLoad (reload )
123- userConf .OnLoad (reload )
124- tokenConf .OnLoad (reload )
124+ defaultsConf .OnReload (reload )
125+ userConf .OnReload (reload )
126+ tokenConf .OnReload (reload )
125127}
126128
127129func InitEnv () {
@@ -139,6 +141,7 @@ func InitEnv() {
139141}
140142
141143func LoadDefaults () {
144+ log .Debug ("Loading defaults " , ENV .DEFAULTS_PATH )
142145 _ , err := defaultsConf .LoadFile (ENV .DEFAULTS_PATH , yaml .Parser ())
143146
144147 if err != nil {
@@ -147,6 +150,7 @@ func LoadDefaults() {
147150}
148151
149152func LoadConfig () {
153+ log .Debug ("Loading Config " , ENV .CONFIG_PATH )
150154 _ , err := userConf .LoadFile (ENV .CONFIG_PATH , yaml .Parser ())
151155
152156 if err != nil {
@@ -161,3 +165,11 @@ func LoadConfig() {
161165 log .Error ("Could not Load Config " , ENV .CONFIG_PATH , ": " , err .Error ())
162166 }
163167}
168+
169+ func normalizeEnv (key string , value string ) (string , any ) {
170+ key = strings .ToLower (key )
171+ key = strings .ReplaceAll (key , "__" , "." )
172+ key = strings .ReplaceAll (key , "_" , "" )
173+
174+ return key , stringutils .ToType (value )
175+ }
0 commit comments