From ae787511f4c9e19e101c125990512de173698139 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 17 Apr 2024 16:55:13 +0300 Subject: [PATCH] fixup load options using Signed-off-by: Vasiliy Tolstov --- file.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/file.go b/file.go index 5a1712f..65c76e2 100644 --- a/file.go +++ b/file.go @@ -81,11 +81,20 @@ func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error { } path := c.path + transformer := c.transformer + reader := c.reader + options := config.NewLoadOptions(opts...) if options.Context != nil { if v, ok := options.Context.Value(pathKey{}).(string); ok && v != "" { path = v } + if v, ok := c.opts.Context.Value(transformerKey{}).(transform.Transformer); ok { + transformer = v + } + if v, ok := c.opts.Context.Value(readerKey{}).(io.Reader); ok { + reader = v + } } var fp io.Reader @@ -94,7 +103,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error { if c.path != "" { fp, err = os.OpenFile(path, os.O_RDONLY, os.FileMode(0o400)) } else if c.reader != nil { - fp = c.reader + fp = reader } else { err = fmt.Errorf("Path or Reader must be specified") } @@ -119,7 +128,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error { } var r io.Reader - if c.transformer != nil { + if transformer != nil { r = transform.NewReader(fp, c.transformer) } else { r = fp