Skip to content

Commit

Permalink
Add option to change parsing strictness on default option
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Nov 9, 2024
1 parent a33d1c7 commit ba21776
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestConfigBasic(t *testing.T) {
"-complex_array", "text1,text2,text3", // Example for ComplexArray (implementsTextUnmarshaler)
}

_, _, err := Config[testStruct](Defaults("testdata/test.json"))
_, _, err := Config[testStruct](Defaults("testdata/test.json", false))
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func Config[T any](suppliedOptions ...option) (result T, warnings []error, err e
}

if len(o.order) == 0 {
if err := Defaults("config.json")(&o); err != nil {
if err := Defaults("config.json", false)(&o); err != nil {
return result, nil, err
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func WithLogLevel(level slog.Level) option {
// The configs struct will be configured config file -> envs -> cli, so that cli takes precedence over more static options, for ease of user configuration.
// The config file will be parsed in a non-strict way (unknown fields will just be ignored) and the config file type is automatically determined from extension (supports yaml, toml and json), if you want to change this, add the FromConfigFile(...) option after Defaults(...)
// path string : config file path
func Defaults(path string) option {
func Defaults(path string, strictConfigFileParsing bool) option {
return func(c *options) error {

// Process in config file -> env -> cli order
Expand Down

0 comments on commit ba21776

Please sign in to comment.