chore(sources/env): bump gosettings to v0.3.0-rc13

- Use `RetroKeys` option with env.* method calls
- Use `CSV*` typed methods
- Inject `handleDeprecatedKey` function
This commit is contained in:
Quentin McGaw
2023-06-05 16:25:52 +00:00
parent 07459ee854
commit a9cd7be3f9
23 changed files with 188 additions and 491 deletions

View File

@@ -8,8 +8,9 @@ import (
)
type Source struct {
env env.Env
warner Warner
env env.Env
warner Warner
handleDeprecatedKey func(deprecatedKey, newKey string)
}
type Warner interface {
@@ -17,9 +18,16 @@ type Warner interface {
}
func New(warner Warner) *Source {
handleDeprecatedKey := func(deprecatedKey, newKey string) {
warner.Warn(
"You are using the old environment variable " + deprecatedKey +
", please consider changing it to " + newKey)
}
return &Source{
env: *env.New(os.Environ()),
warner: warner,
env: *env.New(os.Environ(), handleDeprecatedKey),
warner: warner,
handleDeprecatedKey: handleDeprecatedKey,
}
}
@@ -93,30 +101,3 @@ func (s *Source) Read() (settings settings.Settings, err error) {
return settings, nil
}
func (s *Source) onRetroActive(oldKey, newKey string) {
s.warner.Warn(
"You are using the old environment variable " + oldKey +
", please consider changing it to " + newKey)
}
// getEnvWithRetro returns the first set environment variable
// key and corresponding value from the environment
// variable keys given. It first goes through the retroKeys
// and end on returning the value corresponding to the currentKey.
// Note retroKeys should be in order from oldest to most
// recent retro-compatibility key.
func (s *Source) getEnvWithRetro(currentKey string,
retroKeys []string, options ...env.Option) (key string, value *string) {
// We check retro-compatibility keys first since
// the current key might be set in the Dockerfile.
for _, key = range retroKeys {
value = s.env.Get(key, options...)
if value != nil {
s.onRetroActive(key, currentKey)
return key, value
}
}
return currentKey, s.env.Get(currentKey, options...)
}