etcd

package
v1.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 6 Imported by: 0

README

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/limes-cloud/kratos/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)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(client *clientv3.Client, opts ...Option) (config.Source, error)

Types

type Option

type Option func(o *options)

Option is etcd config option.

func WithContext

func WithContext(ctx context.Context) Option

WithContext with registry context.

func WithPath

func WithPath(p string) Option

WithPath is config path

func WithPrefix

func WithPrefix(prefix bool) Option

WithPrefix is config prefix

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL