From cbd49222f92d4be43cc3d84813a1b3d30263d74c Mon Sep 17 00:00:00 2001 From: Augustin Husson Date: Mon, 18 Dec 2023 15:20:10 +0100 Subject: [PATCH] Set a strict attribute to specify if the unmarshal is stricted Signed-off-by: Augustin Husson --- config/resolver.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/config/resolver.go b/config/resolver.go index 2bd9284..7b6022d 100644 --- a/config/resolver.go +++ b/config/resolver.go @@ -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] { @@ -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) {