Documentation ¶
Index ¶
- Constants
- Variables
- type FileMaintainer
- type GetError
- type MetaConfig
- type OnConfigChange
- type Option
- type Sail
- func (s *Sail) Close() error
- func (s *Sail) Err() error
- func (s *Sail) Get(key string) (interface{}, error)
- func (s *Sail) GetBool(key string) (bool, error)
- func (s *Sail) GetBoolWithName(key string, name string) bool
- func (s *Sail) GetDuration(key string) (time.Duration, error)
- func (s *Sail) GetDurationWithName(key string, name string) time.Duration
- func (s *Sail) GetFloat64(key string) (float64, error)
- func (s *Sail) GetFloat64WithName(key string, name string) float64
- func (s *Sail) GetInt(key string) (int, error)
- func (s *Sail) GetInt32(key string) (int32, error)
- func (s *Sail) GetInt32WithName(key string, name string) int32
- func (s *Sail) GetInt64(key string) (int64, error)
- func (s *Sail) GetInt64WithName(key string, name string) int64
- func (s *Sail) GetIntSlice(key string) ([]int, error)
- func (s *Sail) GetIntSliceWithName(key string, name string) []int
- func (s *Sail) GetIntWithName(key string, name string) int
- func (s *Sail) GetSizeInBytes(key string) (uint, error)
- func (s *Sail) GetSizeInBytesWithName(key string, name string) uint
- func (s *Sail) GetString(key string) (string, error)
- func (s *Sail) GetStringMap(key string) (map[string]interface{}, error)
- func (s *Sail) GetStringMapString(key string) (map[string]string, error)
- func (s *Sail) GetStringMapStringSlice(key string) (map[string][]string, error)
- func (s *Sail) GetStringMapStringSliceWithName(key string, name string) map[string][]string
- func (s *Sail) GetStringMapStringWithName(key string, name string) map[string]string
- func (s *Sail) GetStringMapWithName(key string, name string) map[string]interface{}
- func (s *Sail) GetStringSlice(key string) ([]string, error)
- func (s *Sail) GetStringSliceWithName(key string, name string) []string
- func (s *Sail) GetStringWithName(key string, name string) string
- func (s *Sail) GetTime(key string) (time.Time, error)
- func (s *Sail) GetTimeWithName(key string, name string) time.Time
- func (s *Sail) GetUint(key string) (uint, error)
- func (s *Sail) GetUintWithName(key string, name string) uint
- func (s *Sail) GetViperWithName(name string) *viper.Viper
- func (s *Sail) GetWithName(key string, name string) interface{}
- func (s *Sail) MergeVipers() (*viper.Viper, error)
- func (s *Sail) MergeVipersWithName() (*viper.Viper, error)
- func (s *Sail) MustGet(key string) interface{}
- func (s *Sail) MustGetBool(key string) bool
- func (s *Sail) MustGetDuration(key string) time.Duration
- func (s *Sail) MustGetFloat64(key string) float64
- func (s *Sail) MustGetInt(key string) int
- func (s *Sail) MustGetInt32(key string) int32
- func (s *Sail) MustGetInt64(key string) int64
- func (s *Sail) MustGetIntSlice(key string) []int
- func (s *Sail) MustGetSizeInBytes(key string) uint
- func (s *Sail) MustGetString(key string) string
- func (s *Sail) MustGetStringMap(key string) map[string]interface{}
- func (s *Sail) MustGetStringMapString(key string) map[string]string
- func (s *Sail) MustGetStringMapStringSlice(key string) map[string][]string
- func (s *Sail) MustGetStringSlice(key string) []string
- func (s *Sail) MustGetTime(key string) time.Time
- func (s *Sail) MustGetUint(key string) uint
- func (s *Sail) Pull() error
- type Watcher
Constants ¶
const MergeConfigName = "config.toml"
Variables ¶
var (
ErrDuplicateKey = errors.New("ErrDuplicateKey")
)
Functions ¶
This section is empty.
Types ¶
type FileMaintainer ¶
type FileMaintainer struct {
// contains filtered or unexported fields
}
FileMaintainer 2. 如果设置了ConfigPath,检查Path里有没有配置文件(如果设置了mergeConfig还要merge),有则更新、新增、删除等。(研究是否可以利用Viper) 1. pullETCDConfig后,把viper内的配置全部写成文件。 2. 如果设置mergeConfig,则mergeViper后,再写成文件。 3. 有watch事件,把对应viper的配置重新写成文件。 4. 有mergeConfig,重新mergeViper,覆盖写。 文件默认不加密
func NewFileMaintainer ¶
func NewFileMaintainer(sail *Sail) *FileMaintainer
type MetaConfig ¶
type MetaConfig struct { ETCDEndpoints string `toml:"etcd_endpoints"` // 逗号分隔的ETCD地址,0.0.0.0:2379,0.0.0.0:12379,0.0.0.0:22379 ETCDUsername string `toml:"etcd_username"` ETCDPassword string `toml:"etcd_password"` ProjectKey string `toml:"project_key"` Namespace string `toml:"namespace"` NamespaceKey string `toml:"namespace_key"` Configs string `toml:"configs"` // 逗号分隔的 config_name.config_type,如:mysql.toml,cfg.json,redis.yaml,空代表不下载任何配置 ConfigFilePath string `toml:"config_file_path"` // 本地配置文件存放路径,空代表不存储本都配置文件 LogLevel string `toml:"log_level"` // 日志级别(DEBUG\INFO\WARN\ERROR),默认 WARN MergeConfig bool `toml:"merge_config"` // 是否合并配置,合并配置则会将同类型的配置合并到一个文件中,需要先设置ConfigFilePath }
func (*MetaConfig) SplitConfigs ¶
func (m *MetaConfig) SplitConfigs() []string
func (*MetaConfig) SplitETCDEndpoints ¶
func (m *MetaConfig) SplitETCDEndpoints() []string
type OnConfigChange ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithConfigPath ¶
WithConfigPath 指定备份配置文件的存储路径,为空则不存储备份配置文件
func WithETCDClientConfig ¶
WithETCDClientConfig 自定义的 ETCD 连接配置
func WithLogger ¶
WithLogger 强烈建议替换为自己的Logger,自带的 logger 比较简单
func WithMergeConfig ¶
WithMergeConfig 将所有的配置都合并到一个文件: config.toml 需要先指定 ConfigFilePath
func WithOnConfigChange ¶
func WithOnConfigChange(f OnConfigChange) Option
WithOnConfigChange 配置变更回调 configFileKey 变更的配置文件名 s 更新后的 sail 实例
type Sail ¶
type Sail struct {
// contains filtered or unexported fields
}
func New ¶
func New(meta *MetaConfig, opts ...Option) *Sail
func NewWithEnv ¶
func NewWithFlag ¶
func NewWithToml ¶
func (*Sail) Err ¶
Err 初始化(New)时,失败的 Error 会保存在此处 例: s := sail.New() err := s.Err()
if err != nil{ doing... }
func (*Sail) GetDurationWithName ¶
func (*Sail) GetFloat64WithName ¶
func (*Sail) GetIntSliceWithName ¶
func (*Sail) GetSizeInBytesWithName ¶
func (*Sail) GetStringMapString ¶
func (*Sail) GetStringMapStringSlice ¶
func (*Sail) GetStringMapStringSliceWithName ¶
func (*Sail) GetStringMapStringWithName ¶
func (*Sail) GetStringMapWithName ¶
func (*Sail) GetStringSliceWithName ¶
func (*Sail) GetWithName ¶
func (*Sail) MergeVipers ¶
MergeVipers 把所有配置文件中的配置合并到一个 Viper 实例 如果有重名的配置,则会出现未定义行为,为保证安全,有重名配置请使用 MergeVipersWithName。
func (*Sail) MergeVipersWithName ¶
MergeVipersWithName 把所有配置文件中的配置合并到 Viper 每个配置文件的配置都会加上文件名前缀,所以不怕有重名。 例子: mysql.toml key="va" MergeVipersWithName 后: viper.Get("mysql.toml.key")