Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a strict attribute to specify if the unmarshal is stricted #171

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions config/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,21 @@ type Resolver[T any] interface {
type configResolver[T any] struct {
Resolver[T]
prefix string
strict bool
configFile string
data []byte
watchCallbacks []func(*T)
}

func NewResolver[T any]() Resolver[T] {
return &configResolver[T]{}
return &configResolver[T]{
strict: true,
}
}

func (c *configResolver[T]) Strict(isStrict bool) Resolver[T] {
c.strict = isStrict
return c
}

func (c *configResolver[T]) SetEnvPrefix(prefix string) Resolver[T] {
Expand Down Expand Up @@ -213,7 +221,10 @@ func (c *configResolver[T]) read(config *T) error {
// config can be entirely set from environment
return nil
}
return yaml.UnmarshalStrict(data, config)
if c.strict {
return yaml.UnmarshalStrict(data, config)
}
return yaml.Unmarshal(data, config)
}

func (c *configResolver[T]) watchFile(config *T) {
Expand Down