aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/config.go30
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