Compare commits
1 Commits
feat/recei
...
issue-64-r
| Author | SHA1 | Date | |
|---|---|---|---|
| f32284a39f |
@@ -175,27 +175,35 @@ func envDuration(
|
|||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveEnvironment reads WEBHOOKER_ENVIRONMENT, defaulting to
|
||||||
|
// dev, and rejects unrecognised values.
|
||||||
|
func resolveEnvironment() (string, error) {
|
||||||
|
environment := os.Getenv("WEBHOOKER_ENVIRONMENT")
|
||||||
|
if environment == "" {
|
||||||
|
environment = EnvironmentDev
|
||||||
|
}
|
||||||
|
|
||||||
|
if environment != EnvironmentDev &&
|
||||||
|
environment != EnvironmentProd {
|
||||||
|
return "", fmt.Errorf(
|
||||||
|
"%w: WEBHOOKER_ENVIRONMENT must be '%s' or '%s', got '%s'",
|
||||||
|
ErrInvalidEnvironment,
|
||||||
|
EnvironmentDev, EnvironmentProd, environment,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return environment, nil
|
||||||
|
}
|
||||||
|
|
||||||
// New creates a Config by reading environment variables.
|
// New creates a Config by reading environment variables.
|
||||||
//
|
//
|
||||||
//nolint:revive // lc parameter is required by fx even if unused.
|
//nolint:revive // lc parameter is required by fx even if unused.
|
||||||
func New(lc fx.Lifecycle, params ConfigParams) (*Config, error) {
|
func New(lc fx.Lifecycle, params ConfigParams) (*Config, error) {
|
||||||
log := params.Logger.Get()
|
log := params.Logger.Get()
|
||||||
|
|
||||||
// Determine environment from WEBHOOKER_ENVIRONMENT env var,
|
environment, err := resolveEnvironment()
|
||||||
// default to dev
|
if err != nil {
|
||||||
environment := os.Getenv("WEBHOOKER_ENVIRONMENT")
|
return nil, err
|
||||||
if environment == "" {
|
|
||||||
environment = EnvironmentDev
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate environment
|
|
||||||
if environment != EnvironmentDev &&
|
|
||||||
environment != EnvironmentProd {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"%w: WEBHOOKER_ENVIRONMENT must be '%s' or '%s', got '%s'",
|
|
||||||
ErrInvalidEnvironment,
|
|
||||||
EnvironmentDev, EnvironmentProd, environment,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the retention sweep interval; a set-but-unparseable value
|
// Parse the retention sweep interval; a set-but-unparseable value
|
||||||
|
|||||||
Reference in New Issue
Block a user