fixup load options using
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
6b27204711
commit
e8e336a99f
13
file.go
13
file.go
@ -76,11 +76,20 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
path := c.path
|
path := c.path
|
||||||
|
transformer := c.transformer
|
||||||
|
reader := c.reader
|
||||||
|
|
||||||
options := config.NewLoadOptions(opts...)
|
options := config.NewLoadOptions(opts...)
|
||||||
if options.Context != nil {
|
if options.Context != nil {
|
||||||
if v, ok := options.Context.Value(pathKey{}).(string); ok && v != "" {
|
if v, ok := options.Context.Value(pathKey{}).(string); ok && v != "" {
|
||||||
path = 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
|
var fp io.Reader
|
||||||
@ -89,7 +98,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
|
|||||||
if c.path != "" {
|
if c.path != "" {
|
||||||
fp, err = os.OpenFile(path, os.O_RDONLY, os.FileMode(0o400))
|
fp, err = os.OpenFile(path, os.O_RDONLY, os.FileMode(0o400))
|
||||||
} else if c.reader != nil {
|
} else if c.reader != nil {
|
||||||
fp = c.reader
|
fp = reader
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("Path or Reader must be specified")
|
err = fmt.Errorf("Path or Reader must be specified")
|
||||||
}
|
}
|
||||||
@ -114,7 +123,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
var r io.Reader
|
var r io.Reader
|
||||||
if c.transformer != nil {
|
if transformer != nil {
|
||||||
r = transform.NewReader(fp, c.transformer)
|
r = transform.NewReader(fp, c.transformer)
|
||||||
} else {
|
} else {
|
||||||
r = fp
|
r = fp
|
||||||
|
Loading…
Reference in New Issue
Block a user