etcdcli

package
v1.1.58 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: MIT Imports: 7 Imported by: 0

README

etcdcli

Connect to the etcd service client.

Example of use

    import "github.com/18721889353/sunshine/pkg/etcdcli"

    endpoints := []string{"192.168.3.37:2379"}
    // Way 1: setting parameters
    cli, err := etcdcli.Init(
        endpoints,
        etcdcli.WithConnectTimeout(time.Second*2),
        // etcdcli.WithAutoSyncInterval(0),
        // etcdcli.WithLog(zap.NewNop()),
        // etcdcli.WithAuth("", ""),
    )

    // Way 2: Setting up clientv3.Config
    cli, err = etcdcli.Init(nil, etcdcli.WithConfig(&clientv3.Config{
        Endpoints:   endpoints,
        DialTimeout: time.Second * 2,
        //Username:    "",
        //Password:    "",
    }))

Documentation

Overview

Package etcdcli 用于连接到 etcd 服务

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(endpoints []string, opts ...Option) (*clientv3.Client, error)

Init 连接到 etcd 服务 注意: 如果设置了 WithConfig(*clientv3.Config) 参数,则 endpoints 参数将被忽略!

Types

type Option

type Option func(*options)

Option 用于设置 etcd 客户端的选项。

func WithAuth

func WithAuth(username string, password string) Option

WithAuth 设置认证信息。

func WithAutoSyncInterval

func WithAutoSyncInterval(duration time.Duration) Option

WithAutoSyncInterval 设置成员列表自动同步的时间间隔。

func WithConfig

func WithConfig(c *clientv3.Config) Option

WithConfig 设置 etcd 客户端的配置。

func WithDialTimeout

func WithDialTimeout(duration time.Duration) Option

WithDialTimeout 设置连接超时时间。

func WithLog

func WithLog(l *zap.Logger) Option

WithLog 设置日志记录器。

func WithSecure

func WithSecure(serverNameOverride string, certFile string) Option

WithSecure 设置 TLS 安全连接。

Jump to

Keyboard shortcuts

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