https://github.com/trpc-ecosystem/go-config-etcd
tRPC-Go etcd configuration plugin
https://github.com/trpc-ecosystem/go-config-etcd
Last synced: 3 months ago
JSON representation
tRPC-Go etcd configuration plugin
- Host: GitHub
- URL: https://github.com/trpc-ecosystem/go-config-etcd
- Owner: trpc-ecosystem
- License: other
- Created: 2023-08-29T07:26:42.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T12:05:34.000Z (over 1 year ago)
- Last Synced: 2025-03-28T07:02:00.557Z (3 months ago)
- Language: Go
- Size: 48.8 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE-OF-CONDUCT.md
Awesome Lists containing this project
README
English | [中文](README_CN.md)
# tRPC-Go etcd configuration plugin
[](https://pkg.go.dev/github.com/trpc-ecosystem/go-config-etcd)
[](https://goreportcard.com/report/trpc.group/trpc-go/trpc-config-etcd)
[](https://github.com/trpc-ecosystem/go-config-etcd/blob/main/LICENSE)
[](https://github.com/trpc-ecosystem/go-config-etcd/releases)
[](https://github.com/trpc-ecosystem/go-config-etcd/actions/workflows/prc.yml)
[](https://app.codecov.io/gh/trpc-ecosystem/go-config-etcd/tree/main)The plugin encapsulates [etcd-client](https://github.com/etcd-io/etcd/tree/main/client/v3), facilitating rapid access to configurations in etcd within the tRPC-Go framework.
## Get started
### Step 1
Anonymous import this package
```go
import _ "trpc.group/trpc-go/trpc-config-etcd"
```### Step 2
In the trpc_go.yaml configuration file, set the Endpoint and Dialtimeout, for the complete configuration, refer to [Config](https://github.com/etcd-io/etcd/blob/client/v3.5.9/client/v3/config.go#L26)
```yaml
plugins:
config:
etcd:
endpoints:
- localhost:2379
dialtimeout: 5s
```### Step 3
After calling trpc.NewServer, retrieve the etcd configuration item.
```go
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())
}
}
```## Notes
The plugin currently only supports reading configurations, and the Get and Put functions are not yet implemented.