config: remove default config (#1882)

Co-authored-by: Asim Aslam <asim@aslam.me>
This commit is contained in:
ben-toogood 2020-07-28 13:54:58 +01:00 committed by GitHub
parent c6163bb22f
commit 9813f98c8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 50 deletions

View File

@ -7,7 +7,6 @@ import (
"github.com/micro/go-micro/v3/config/loader" "github.com/micro/go-micro/v3/config/loader"
"github.com/micro/go-micro/v3/config/reader" "github.com/micro/go-micro/v3/config/reader"
"github.com/micro/go-micro/v3/config/source" "github.com/micro/go-micro/v3/config/source"
"github.com/micro/go-micro/v3/config/source/file"
) )
// Config is an interface abstraction for dynamic configuration // Config is an interface abstraction for dynamic configuration
@ -45,54 +44,7 @@ type Options struct {
type Option func(o *Options) type Option func(o *Options)
var (
// Default Config Manager
DefaultConfig, _ = NewConfig()
)
// NewConfig returns new config // NewConfig returns new config
func NewConfig(opts ...Option) (Config, error) { func NewConfig(opts ...Option) (Config, error) {
return newConfig(opts...) return newConfig(opts...)
} }
// Return config as raw json
func Bytes() []byte {
return DefaultConfig.Bytes()
}
// Return config as a map
func Map() map[string]interface{} {
return DefaultConfig.Map()
}
// Scan values to a go type
func Scan(v interface{}) error {
return DefaultConfig.Scan(v)
}
// Force a source changeset sync
func Sync() error {
return DefaultConfig.Sync()
}
// Get a value from the config
func Get(path ...string) reader.Value {
return DefaultConfig.Get(path...)
}
// Load config sources
func Load(source ...source.Source) error {
return DefaultConfig.Load(source...)
}
// Watch a value for changes
func Watch(path ...string) (Watcher, error) {
return DefaultConfig.Watch(path...)
}
// LoadFile is short hand for creating a file source and loading it
func LoadFile(path string) error {
return Load(file.NewSource(
file.WithPath(path),
))
}

View File

@ -33,9 +33,11 @@ type watcher struct {
func newConfig(opts ...Option) (Config, error) { func newConfig(opts ...Option) (Config, error) {
var c config var c config
c.Init(opts...) if err := c.Init(opts...); err != nil {
go c.run() return nil, err
}
go c.run()
return &c, nil return &c, nil
} }