Skip to content

Commit

Permalink
Set a strict attribute to specify if the unmarshal is stricted (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Husson <[email protected]>
  • Loading branch information
Nexucis authored Dec 18, 2023
1 parent 9ae95fb commit a9cce65
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit a9cce65

Please sign in to comment.