2019-05-31 01:11:13 +03:00
|
|
|
package reader
|
|
|
|
|
|
|
|
import (
|
2020-07-27 15:22:00 +03:00
|
|
|
"github.com/micro/go-micro/v3/config/encoder"
|
|
|
|
"github.com/micro/go-micro/v3/config/encoder/hcl"
|
|
|
|
"github.com/micro/go-micro/v3/config/encoder/json"
|
|
|
|
"github.com/micro/go-micro/v3/config/encoder/toml"
|
|
|
|
"github.com/micro/go-micro/v3/config/encoder/xml"
|
|
|
|
"github.com/micro/go-micro/v3/config/encoder/yaml"
|
2019-05-31 01:11:13 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
2020-07-06 22:13:35 +03:00
|
|
|
Encoding map[string]encoder.Encoder
|
|
|
|
DisableReplaceEnvVars bool
|
2019-05-31 01:11:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
func NewOptions(opts ...Option) Options {
|
|
|
|
options := Options{
|
|
|
|
Encoding: map[string]encoder.Encoder{
|
|
|
|
"json": json.NewEncoder(),
|
|
|
|
"yaml": yaml.NewEncoder(),
|
|
|
|
"toml": toml.NewEncoder(),
|
|
|
|
"xml": xml.NewEncoder(),
|
|
|
|
"hcl": hcl.NewEncoder(),
|
|
|
|
"yml": yaml.NewEncoder(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithEncoder(e encoder.Encoder) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
if o.Encoding == nil {
|
|
|
|
o.Encoding = make(map[string]encoder.Encoder)
|
|
|
|
}
|
|
|
|
o.Encoding[e.String()] = e
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 22:13:35 +03:00
|
|
|
|
|
|
|
// WithDisableReplaceEnvVars disables the environment variable interpolation preprocessor
|
|
|
|
func WithDisableReplaceEnvVars() Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.DisableReplaceEnvVars = true
|
|
|
|
}
|
|
|
|
}
|