ParseConfig loads configuration from known paths.
(cfg *config.Config)
| 15 | |
| 16 | // ParseConfig loads configuration from known paths. |
| 17 | func ParseConfig(cfg *config.Config) error { |
| 18 | err := occfg.BindSourcesToStructs(cfg.Service.Name, cfg) |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | |
| 23 | defaults.EnsureDefaults(cfg) |
| 24 | |
| 25 | // load all env variables relevant to the config in the current context. |
| 26 | if err := envdecode.Decode(cfg); err != nil { |
| 27 | // no environment variable set for this config is an expected "error" |
| 28 | if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) { |
| 29 | return err |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | defaults.Sanitize(cfg) |
| 34 | |
| 35 | return Validate(cfg) |
| 36 | } |
| 37 | |
| 38 | // Validate validates the config |
| 39 | func Validate(cfg *config.Config) error { |
no test coverage detected