etcd

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0, MIT Imports: 5 Imported by: 2

README

English | 中文

tRPC-Go etcd configuration plugin

Go Reference Go Report Card LICENSE Releases Docs Tests Coverage

The plugin encapsulates etcd-client, facilitating rapid access to configurations in etcd within the tRPC-Go framework.

Get started

Step 1

Anonymous import this package

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

plugins:                 
  config:
    etcd:
      endpoints:
        - localhost:2379
      dialtimeout: 5s
Step 3

After calling trpc.NewServer, retrieve the etcd configuration item.

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented not implemented error

Functions

func NewPlugin

func NewPlugin() plugin.Factory

NewPlugin initializes the plugin.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client etcd client.

func New

func New(cfg clientv3.Config) (*Client, error)

New creates an etcd client instance.

func (*Client) Del

func (c *Client) Del(ctx context.Context, key string, opts ...config.Option) error

Del deletes the configuration item key and implement the config.KV interface.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string, _ ...config.Option) (config.Response, error)

Get Obtains the configuration content value according to the key, and implement the config.KV interface.

func (*Client) Name

func (c *Client) Name() string

Name returns plugin name.

func (*Client) Put

func (c *Client) Put(ctx context.Context, key, val string, opts ...config.Option) error

Put creates or updates the configuration content value to implement the config.KV interface.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, key string, opts ...config.Option) (<-chan config.Response, error)

Watch monitors configuration changes and implements the config.Watcher interface.

Jump to

Keyboard shortcuts

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