1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-02-21 19:19:32 +02:00
dependabot[bot] 192e493eef
build(deps): bump google.golang.org/grpc in /contrib/config/etcd (#3046)
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.57.0 to 1.59.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.57.0...v1.59.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Weizhen Wang <wangweizhen@pingcap.com>
2023-11-27 15:49:00 +08:00
..
2022-09-27 14:08:08 +08:00
2022-09-27 14:08:08 +08:00

Etcd Config

import (
	"log"

	clientv3 "go.etcd.io/etcd/client/v3"
	"google.golang.org/grpc"

	cfg "github.com/go-kratos/kratos/contrib/config/etcd/v2"
	"github.com/go-kratos/kratos/v2/config"
)

// create an 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()

// load sources before get
if err := c.Load(); err != nil {
    log.Fatalln(err)
}

// acquire config value
foo, err := c.Value("/app-config").String()
if err != nil {
    log.Fatalln(err)
}

log.Println(foo)