From 780a6c0527bcb29ccccac5fe4b7c6f5f608fa1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=91=AB?= Date: Fri, 12 Nov 2021 23:16:50 +0800 Subject: [PATCH] docs of etcd config (#1622) --- contrib/config/etcd/README.md | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 contrib/config/etcd/README.md diff --git a/contrib/config/etcd/README.md b/contrib/config/etcd/README.md new file mode 100644 index 000000000..c6f3f1bd5 --- /dev/null +++ b/contrib/config/etcd/README.md @@ -0,0 +1,41 @@ +# Etcd Config + +```go +import ( + "log" + + cfg "github.com/go-kratos/kratos/contrib/config/etcd/v2" + "github.com/go-kratos/kratos/v2/config" + clientv3 "go.etcd.io/etcd/client/v3" + "google.golang.org/grpc" +) + +// create a etcd client +client, err := clientv3.New(clientv3.Config{ + Endpoints: []string{"127.0.0.1:2379"}, + DialTimeout: time.Second, + DialOptions: []grpc.DialOption{grpc.WithBlock()}, +}) +if err != nil { + log.Fatal(err) +} + +// configure the source, "path" is required +source, err := cfg.New(client, cfg.WithPath("/app-config"), cfg.WithPrefix(true)) +if err != nil { + log.Fatalln(err) +} + +// create a config instance with source +c := config.New(config.WithSource(source)) +defer c.Close() + +// acquire config value +foo, err := c.Value("/app-config").String() +if err != nil { + log.Println(err) +} +println(foo) + +``` +