Option to allow setting empty values
- Dominant language
- Go
- Stars
- 6.3k
- Forks
- 284
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 1
Description
I would like to be able to use environment variables to set a default value to an empty string if the environment variable is set:
```go
type MyConfig struct {
Variable string `env:"VARIABLE"`
}
func NewConfig() (*MyConfig, error) {
cfg := &MyConfig{
Variable: "default",
}
if err := env.Parse(cfg); err != nil {
return nil, err
}
return cfg, nil
}
```
If `VARIABLE=""` is set, the env package would just completely skip overwriting the default value to become empty as well.
Basically, I would like to have an option to skip this empty check here:
https://github.com/caarlos0/env/blob/3a3ea05453bd16685c807ba089b20a82033a02f1/env.go#L507-L509
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in env.go at the linked empty-value check around lines 507-509. Trace how environment values are applied to struct fields and identify the existing option pattern, then verify that an explicitly set empty VARIABLE can replace the default while the current behavior remains unchanged without the option.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100