English | 中文
The plugin encapsulates etcd-client, facilitating rapid access to configurations in etcd within the tRPC-Go framework.
Anonymous import this package
import _ "trpc.group/trpc-go/trpc-config-etcd"
In the trpc_go.yaml configuration file, set the Endpoint and Dialtimeout, for the complete configuration, refer to Config
plugins:
config:
etcd:
endpoints:
- localhost:2379
dialtimeout: 5s
After calling trpc.NewServer, retrieve the etcd configuration item.
func main() {
trpc.NewServer()
// Get the configuration item with the key "foo"
value, err := config.GetString("foo")
if err != nil {
panic(err)
}
fmt.Println(value)
// Watch changes to the configuration item with the key "foo"
ch, err := config.Get("etcd").Watch(context.Background(), "foo")
if err != nil {
panic(err)
}
for rsp := range ch {
fmt.Println(rsp.Value())
}
}
The plugin currently only supports reading configurations, and the Get and Put functions are not yet implemented.