github.com/esnet/gdg@v0.6.1-0.20240412190737-6b6eba9c14d8/internal/config/globals.go (about) 1 package config 2 3 import ( 4 "log/slog" 5 "time" 6 ) 7 8 // AppGlobals is the global configuration for the application 9 type AppGlobals struct { 10 Debug bool `mapstructure:"debug" yaml:"debug"` 11 IgnoreSSLErrors bool `mapstructure:"ignore_ssl_errors" yaml:"ignore_ssl_errors"` 12 RetryCount int `mapstructure:"retry_count" yaml:"retry_count"` 13 RetryDelay string `mapstructure:"retry_delay" yaml:"retry_delay"` 14 retryTimeout *time.Duration `mapstructure:"-" yaml:"-"` 15 } 16 17 // GetRetryTimeout returns 100ms, by default otherwise the parsed value 18 func (app *AppGlobals) GetRetryTimeout() time.Duration { 19 defaultBehavior := func() { 20 d := time.Millisecond * 100 21 app.retryTimeout = &d 22 } 23 if app.RetryDelay == "" { 24 defaultBehavior() 25 } 26 if app.retryTimeout != nil { 27 return *app.retryTimeout 28 } 29 d, err := time.ParseDuration(app.RetryDelay) 30 if err != nil { 31 slog.Warn("Unable to parse the retry_delay value. Falling back on default to 100ms") 32 defaultBehavior() 33 } else { 34 app.retryTimeout = &d 35 } 36 37 return *app.retryTimeout 38 39 }