You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
kratos/contrib/config/etcd
Cluas 4f8d8ef8da
feat(config): add ErrorWatcherStopped and return on watcher.Next() after Watcher.Stop() (#2092)
3 years ago
..
README.md docs of etcd config (#1622) 3 years ago
config.go fix: delete redundant type conversion (#1977) 3 years ago
config_test.go test:remove testify go mod (#1766) 3 years ago
go.mod deps: upgrade kratos version to v.2.3.1 (#2075) 3 years ago
go.sum deps: upgrade go mod version (#2028) 3 years ago
watcher.go feat(config): add ErrorWatcherStopped and return on watcher.Next() after Watcher.Stop() (#2092) 3 years ago

README.md

Etcd Config

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)