Closed ajatprabha closed 1 week ago
When a key is missing that has a prefix as well, in that case, collision detection reports a false positive. The latter example shows how missing key SERVER_ADDRESS causes the error output.
SERVER_ADDRESS
panic: xload: key collisions detected for keys: [SERVER_]
Issue
When a key is missing that has a prefix as well, in that case, collision detection reports a false positive. The latter example shows how missing key
SERVER_ADDRESS
causes the error output.Working example
```go package main import ( "context" "fmt" "time" "github.com/gojekfarm/xtools/xload" xloadtype "github.com/gojekfarm/xtools/xload/type" ) type Pprof struct { Enabled bool `env:"ENABLED"` Address xloadtype.Listener `env:"ADDRESS"` } type ServerConfig struct { HTTP *xloadtype.Listener `env:"ADDRESS"` } type Config struct { Pprof Pprof `env:",prefix=PPROF_"` Server ServerConfig `env:",prefix=SERVER_"` ShutdownDelay time.Duration `env:"SHUTDOWN_DELAY"` } func main() { ml := xload.MapLoader{ "LOG_ENABLED": "true", "LOG_LEVEL": "debug", "PPROF_ENABLED": "true", "PPROF_ADDRESS": ":9090", "SHUTDOWN_DELAY": "4s", "SERVER_ADDRESS": ":8000", } cfg := new(Config) if err := xload.Load(context.TODO(), cfg, xload.SerialLoader(ml, xload.OSLoader()), ); err != nil { panic(err) } fmt.Printf("%+v\n", cfg) } ```Problematic Example
```go package main import ( "context" "fmt" "time" "github.com/gojekfarm/xtools/xload" xloadtype "github.com/gojekfarm/xtools/xload/type" ) type Pprof struct { Enabled bool `env:"ENABLED"` Address xloadtype.Listener `env:"ADDRESS"` } type ServerConfig struct { HTTP *xloadtype.Listener `env:"ADDRESS"` } type Config struct { Pprof Pprof `env:",prefix=PPROF_"` Server ServerConfig `env:",prefix=SERVER_"` ShutdownDelay time.Duration `env:"SHUTDOWN_DELAY"` } func main() { ml := xload.MapLoader{ "LOG_ENABLED": "true", "LOG_LEVEL": "debug", "PPROF_ENABLED": "true", "PPROF_ADDRESS": ":9090", "SHUTDOWN_DELAY": "4s", //"SERVER_ADDRESS": ":8000", } cfg := new(Config) if err := xload.Load(context.TODO(), cfg, xload.SerialLoader(ml, xload.OSLoader()), ); err != nil { panic(err) } fmt.Printf("%+v\n", cfg) } ```