Skip to content

Latest commit

 

History

History
65 lines (48 loc) · 2.06 KB

README.zh_CN.md

File metadata and controls

65 lines (48 loc) · 2.06 KB

English | 中文

tRPC-Go etcd 配置插件

Go Reference Go Report Card LICENSE Releases Tests Coverage

插件封装了 etcd-client,便于在 tRPC-Go 框架中快速访问 etcd 中的配置。

使用方法

第一步

匿名 import 此包

import _ "trpc.group/trpc-go/trpc-config-etcd"

第二步

在 trpc_go.yaml 配置文件中设置 Endpoint 和 Dialtimeout 信息,完整配置见 Config

plugins:                 
  config:
    etcd:
      endpoints:
        - localhost:2379
      dialtimeout: 5s

第三步

在 trpc.NewServer 之后,获取 etcd 配置信息

func main() {
	trpc.NewServer()

    // 获取 key 为 "foo" 的配置项
	value, err := config.GetString("foo")
	if err != nil {
		panic(err)
	}
	fmt.Println(value)

    // 监听 key 为 "foo" 的配置项变化
	ch, err := config.Get("etcd").Watch(context.Background(), "foo")
	if err != nil {
		panic(err)
	}
	for rsp := range ch {
		fmt.Println(rsp.Value())
	}
}

注意事项

插件暂时只支持读取配置,Get、Put 功能暂未实现。