etcd

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 9 Imported by: 0

README

etcd实现服务注册和发现

etcd是一个开源的、高可用的分布式key-value存储系统,可以用于配置共享和服务的注册和发现。

本地运行etcd

docker run -d \
  --name etcd_test \
  --restart=always \
  -p 12379:2379 \
  -p 12380:2380 \
  quay.io/coreos/etcd:v3.5.1 \
  /usr/local/bin/etcd \
  --name etcd_test \
  --data-dir /etcd-data \
  --advertise-client-urls http://0.0.0.0:2379 \
  --listen-client-urls http://0.0.0.0:2379

服务注册和发现使用

参考registry_test.go文件

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDiscovery

func NewDiscovery(endpoints []string, opts ...Option) (hestia.Discovery, error)

NewDiscovery create a registry interface instance

func NewRegistry

func NewRegistry(endpoints []string, opts ...Option) (hestia.Registry, error)

NewRegistry create a registry interface instance

Types

type Option

type Option func(*Options)

Option etcdImpl functional option

func WithDialTimeout

func WithDialTimeout(dialTimeout time.Duration) Option

WithDialTimeout set dialTimeout

func WithEnableWatched added in v1.1.2

func WithEnableWatched() Option

WithEnableWatched set discover watch

func WithLeaseTTL

func WithLeaseTTL(ttl int64) Option

WithLeaseTTL set etcd lease ttl

func WithPassword

func WithPassword(password string) Option

WithPassword 设置 password

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix set etcd prefix

func WithUsername

func WithUsername(username string) Option

WithUsername 设置 username

type Options

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

Options etcd options

Jump to

Keyboard shortcuts

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