diff options
author | dakkar <dakkar@thenautilus.net> | 2024-12-19 15:16:56 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2024-12-19 15:18:37 +0000 |
commit | cafc27302d7fdf69934f3b5007ddf3f5e0fc1cd4 (patch) | |
tree | 6164fa82fb8f52b6eb47d06e36f9f97442e4569d /config/config.go | |
parent | move more code in the factory (diff) | |
download | go-example-master.tar.gz go-example-master.tar.bz2 go-example-master.zip |
Diffstat (limited to 'config/config.go')
-rw-r--r-- | config/config.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/config/config.go b/config/config.go index c28fa14..c4755f6 100644 --- a/config/config.go +++ b/config/config.go @@ -24,18 +24,28 @@ func (c *LoggerConfig) MarshalZerologObject(e *zerolog.Event) { Str("format", c.Format) } -type SomethingConfig struct { +type SomethingClientConfig struct { Value int `mapstructure:"value"` } -func (c *SomethingConfig) MarshalZerologObject(event *zerolog.Event) { +func (c *SomethingClientConfig) MarshalZerologObject(event *zerolog.Event) { event. Int("value", c.Value) } +type BusinessLogicConfig struct { + Threshold int `mapstructure:"threshold"` +} + +func (c *BusinessLogicConfig) MarshalZerologObject(event *zerolog.Event) { + event. + Int("threshold", c.Threshold) +} + type MainConfig struct { - Something SomethingConfig `mapstructure:"something"` - Logger LoggerConfig `mapstructure:"logger"` + Something SomethingClientConfig `mapstructure:"something"` + BusinessLogic BusinessLogicConfig `mapstructure:"bl"` + Logger LoggerConfig `mapstructure:"logger"` configFile string } @@ -44,7 +54,8 @@ func (c *MainConfig) MarshalZerologObject(event *zerolog.Event) { event. Str("config-file", c.configFile). Object("logger", &c.Logger). - Object("something", &c.Something) + Object("something", &c.Something). + Object("bl", &c.BusinessLogic) } func addLoggerOptions() { @@ -55,11 +66,17 @@ func addLoggerOptions() { } func addSomethingOptions() { - pflag.Int("something-value", 123, "value used to do something") + pflag.Int("something-value", 123, "value of something") viper.BindPFlag("something.value", pflag.Lookup("something-value")) //nolint:errcheck viper.BindEnv("something.value", "SOMETHING_VALUE") //nolint:errcheck } +func addBLOptions() { + pflag.Int("bl-threshold", 100, "threshold for a business logic action") + viper.BindPFlag("bl.threshold", pflag.Lookup("bl-threshold")) //nolint:errcheck + viper.BindEnv("bl.threshold", "BUSINESS_THRESHOLD") //nolint:errcheck +} + func addConfigFromFile(configRelPath string) error { mode := os.Getenv("RUN_MODE") if mode == "" { @@ -118,6 +135,7 @@ func loadConfigFromFile() (MainConfig, error) { func GetMainConfig() (MainConfig, error) { addLoggerOptions() addSomethingOptions() + addBLOptions() pflag.Parse() viper.BindPFlags(pflag.CommandLine) //nolint:errcheck |