go-common/library/conf/paladin
2019-04-22 18:49:16 +08:00
..
BUILD Create & Init Project... 2019-04-22 18:49:16 +08:00
CHANGELOG.md Create & Init Project... 2019-04-22 18:49:16 +08:00
client.go Create & Init Project... 2019-04-22 18:49:16 +08:00
CONTRIBUTORS.md Create & Init Project... 2019-04-22 18:49:16 +08:00
default.go Create & Init Project... 2019-04-22 18:49:16 +08:00
example_test.go Create & Init Project... 2019-04-22 18:49:16 +08:00
file_test.go Create & Init Project... 2019-04-22 18:49:16 +08:00
file.go Create & Init Project... 2019-04-22 18:49:16 +08:00
helper.go Create & Init Project... 2019-04-22 18:49:16 +08:00
map_test.go Create & Init Project... 2019-04-22 18:49:16 +08:00
map.go Create & Init Project... 2019-04-22 18:49:16 +08:00
mock_test.go Create & Init Project... 2019-04-22 18:49:16 +08:00
mock.go Create & Init Project... 2019-04-22 18:49:16 +08:00
OWNERS Create & Init Project... 2019-04-22 18:49:16 +08:00
README.md Create & Init Project... 2019-04-22 18:49:16 +08:00
sven_test.go Create & Init Project... 2019-04-22 18:49:16 +08:00
sven.go Create & Init Project... 2019-04-22 18:49:16 +08:00
toml.go Create & Init Project... 2019-04-22 18:49:16 +08:00
value_test.go Create & Init Project... 2019-04-22 18:49:16 +08:00
value.go Create & Init Project... 2019-04-22 18:49:16 +08:00

paladin

项目简介

paladin 是一个config SDK客户端包括了sven、file、mock几个抽象功能方便使用本地文件或者sven配置中心并且集成了对象自动reload功能。

sven:

caster配置项
配置地址CONF_HOST: config.bilibili.co
配置版本CONF_VERSION: docker-1/server-1
配置路径CONF_PATH: /data/conf/app
配置TokenCONF_TOKEN: token
配置指定版本CONF_APPOINT: 27600

依赖环境变量:
TREE_ID/DEPLOY_ENV/ZONE/HOSTNAME/POD_IP

local files:

/data/app/msm-service -conf=/data/conf/app/msm-servie.toml
// or multi file
/data/app/msm-service -conf=/data/conf/app/

example:

type exampleConf struct {
	Bool   bool
	Int    int64
	Float  float64
	String string
}

func (e *exampleConf) Set(text string) error {
	var ec exampleConf
	if err := toml.Unmarshal([]byte(text), &ec); err != nil {
		return err
	}
	*e = ec
	return nil
}

func ExampleClient() {
	if err := paladin.Init(); err != nil {
		panic(err)
	}
	var (
		ec   exampleConf
		eo   exampleConf
		m    paladin.TOML
		strs []string
	)
	// config unmarshal
	if err := paladin.Get("example.toml").UnmarshalTOML(&ec); err != nil {
		panic(err)
	}
	// config setter
	if err := paladin.Watch("example.toml", &ec); err != nil {
        panic(err)
    }
	// paladin map
	if err := paladin.Watch("example.toml", &m); err != nil {
        panic(err)
    }
	s, err := m.Value("key").String()
	b, err := m.Value("key").Bool()
	i, err := m.Value("key").Int64()
	f, err := m.Value("key").Float64()
	// value slice
	err = m.Value("strings").Slice(&strs)
	// watch key
	for event := range paladin.WatchEvent(context.TODO(), "key") {
		fmt.Println(event)
	}
}
编译环境
  • 请只用 Golang v1.8.x 以上版本编译执行
依赖包
  1. github.com/naoina/toml
  2. github.com/pkg/errors