1 Star 0 Fork 0

宁成增/base-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config.go 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
宁成增 提交于 2021-01-11 20:33 +08:00 . init
// Package config is an interface for dynamic configuration.
package config
import (
"context"
"gitee.com/psdnfu/base-core/config/loader"
"gitee.com/psdnfu/base-core/config/reader"
"gitee.com/psdnfu/base-core/config/source"
"gitee.com/psdnfu/base-core/config/source/file"
)
// Config is an interface abstraction for dynamic configuration
type Config interface {
// provide the reader.Values interface
reader.Values
// Init the config
Init(opts ...Option) error
// Options in the config
Options() Options
// Stop the config loader/watcher
Close() error
// Load config sources
Load(source ...source.Source) error
// Force a source changeset sync
Sync() error
// Watch a value for changes
Watch(path ...string) (Watcher, error)
}
// Watcher is the config watcher
type Watcher interface {
Next() (reader.Value, error)
Stop() error
}
type Options struct {
Loader loader.Loader
Reader reader.Reader
Source []source.Source
// for alternative data
Context context.Context
}
type Option func(o *Options)
var (
// Default Config Manager
DefaultConfig, _ = NewConfig()
)
// NewConfig returns new config
func NewConfig(opts ...Option) (Config, error) {
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),
))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/psdnfu/base-core.git
git@gitee.com:psdnfu/base-core.git
psdnfu
base-core
base-core
v0.0.1

搜索帮助