hconf

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

基于etcd与viper的高可用配置中心

  • 可使用远程与本地模式
  • 本地有的配置远程没有会自动把本地配置传到远程(基于key)
  • 远程有的配置本地没有也会写一份到本地(退出程序会把远程配置写一份到本地)
  • 远程模式配置可以动态加载
  • 如远程连接不上会使用本地配置启动作为兜底
var conf = Conf{}
r, err := NewHConf(
	SetWatchRootName([]string{"/gs/conf"}),
)
if err != nil {
	t.Error(err)
	return
}
t.Log(r.ConfByKey("/gs/conf/net", &conf.Net))
t.Log(r.ConfByKey("/gs/conf/net2222", &conf.Net2))
t.Log(r.ConfByKey("/gs/conf/net3333", &conf.Net3))
if err := r.Run(); err != nil {
	t.Error(err)
	return
}
t.Log(conf)
t.Log(r.Close())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	EtcdConf        clientv3.Config
	EtcdReadTimeOut time.Duration
	LocalConfName   string
	UseLocal        bool
	WatchRootName   []string
}

func (*Options) UseLocalConf

func (p *Options) UseLocalConf() bool

type Register

type Register interface {
	ConfByKey(key string, val interface{}) error
	Run() error
	Close() error
}

func NewHConf

func NewHConf(opt ...RegisterOptions) (Register, error)

type RegisterOptions

type RegisterOptions func(*Options)

func SetEtcdConf

func SetEtcdConf(conf clientv3.Config) RegisterOptions

func SetEtcdReadTimeOut

func SetEtcdReadTimeOut(t time.Duration) RegisterOptions

func SetLocalConfName

func SetLocalConfName(name string) RegisterOptions

func SetUseLocal

func SetUseLocal() RegisterOptions

func SetWatchRootName

func SetWatchRootName(name []string) RegisterOptions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL