Compare commits
1 Commits
issue-64-r
...
feat/recei
| Author | SHA1 | Date | |
|---|---|---|---|
| 8cf9d0525a |
@@ -175,35 +175,27 @@ 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()
|
||||||
|
|
||||||
environment, err := resolveEnvironment()
|
// Determine environment from WEBHOOKER_ENVIRONMENT env var,
|
||||||
if err != nil {
|
// default to dev
|
||||||
return nil, err
|
environment := os.Getenv("WEBHOOKER_ENVIRONMENT")
|
||||||
|
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