2019-05-31 00:11:13 +02:00
|
|
|
package file
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-24 02:46:18 +02:00
|
|
|
"io/fs"
|
2019-05-31 00:11:13 +02:00
|
|
|
|
2021-10-12 13:55:53 +02:00
|
|
|
"go-micro.dev/v4/config/source"
|
2019-05-31 00:11:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type filePathKey struct{}
|
2022-09-24 02:46:18 +02:00
|
|
|
type fsKey struct{}
|
2019-05-31 00:11:13 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// WithPath sets the path to file.
|
2019-05-31 00:11:13 +02:00
|
|
|
func WithPath(p string) source.Option {
|
|
|
|
return func(o *source.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, filePathKey{}, p)
|
|
|
|
}
|
|
|
|
}
|
2022-09-24 02:46:18 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// WithFS sets the underlying filesystem to lookup file from (default os.FS).
|
2022-09-24 02:46:18 +02:00
|
|
|
func WithFS(fs fs.FS) source.Option {
|
|
|
|
return func(o *source.Options) {
|
|
|
|
if o.Context == nil {
|
|
|
|
o.Context = context.Background()
|
|
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, fsKey{}, fs)
|
|
|
|
}
|
|
|
|
}
|