etcd

package
v0.0.131 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

Index

Constants

View Source
const (
	DefaultDialTimeout = 5 * time.Second
	DefaultLockTTL     = 15 * time.Second
)

Default values for Etcd.

Variables

View Source
var File_pkg_discovery_etcd_etcd_proto protoreflect.FileDescriptor

Functions

func CloseKV

func CloseKV() error

func GetKV

func GetKV() *clientv3.Client

func Watch

func Watch(ctx context.Context, kv *clientv3.Client, key string, createCallbackFunc, deleteCallbackFunc EventCallbackFunc)

Types

type CompletedConfig

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

func (CompletedConfig) New

func (c CompletedConfig) New(ctx context.Context, createCallbackFunc, deleteCallbackFunc EventCallbackFunc) (*EtcdKV, error)

type Config

type Config struct {
	Proto Etcd
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(options ...ConfigOption) *Config

func (*Config) ApplyOptions

func (o *Config) ApplyOptions(options ...ConfigOption) *Config

func (*Config) Complete

func (c *Config) Complete() CompletedConfig

Complete set default ServerRunOptions.

type ConfigOption

type ConfigOption interface {
	// contains filtered or unexported methods
}

A ConfigOption sets options.

func WithViper

func WithViper(v *viper.Viper) ConfigOption

type ConfigOptionFunc

type ConfigOptionFunc func(*Config)

ConfigOptionFunc wraps a function that modifies Client into an implementation of the ConfigOption interface.

type ETCDKV

type ETCDKV atomic.Value

func (*ETCDKV) Load

func (m *ETCDKV) Load() *clientv3.Client

func (*ETCDKV) Store

func (m *ETCDKV) Store(value *clientv3.Client)

type EmptyConfigOption

type EmptyConfigOption struct{}

EmptyConfigOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyEtcdKVOption

type EmptyEtcdKVOption struct{}

EmptyEtcdKVUrlOption does not alter the EtcdKVuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type Etcd

type Etcd struct {
	Enabled            bool     `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"`
	Addresses          []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"`
	Username           string   `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"`
	Password           string   `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"`
	MaxCallSendMsgSize int32    `protobuf:"varint,5,opt,name=max_call_send_msg_size,json=maxCallSendMsgSize,proto3" json:"max_call_send_msg_size,omitempty"` //If 0, it defaults to 2.0 MiB (2 * 1024 * 1024)
	// MaxCallRecvMsgSize is the client-side response receive limit.
	// If 0, it defaults to "math.MaxInt32", because range response can
	// easily exceed request send limits.
	// Make sure that "MaxCallRecvMsgSize" >= server-side default
	// send/recv limit.
	// ("--max-request-bytes" flag to etcd or
	// "embed.Config.MaxRequestBytes").
	MaxCallRecvMsgSize int32 `protobuf:"varint,6,opt,name=max_call_recv_msg_size,json=maxCallRecvMsgSize,proto3" json:"max_call_recv_msg_size,omitempty"`
	// AutoSyncInterval is the interval to update endpoints with its latest members.
	// 0 disables auto-sync. By default auto-sync is disabled.
	AutoSyncInterval  *durationpb.Duration `protobuf:"bytes,7,opt,name=auto_sync_interval,json=autoSyncInterval,proto3" json:"auto_sync_interval,omitempty"`
	DialTimeout       *durationpb.Duration `protobuf:"bytes,8,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"`
	MaxWaitDuration   *durationpb.Duration `protobuf:"bytes,12,opt,name=max_wait_duration,json=maxWaitDuration,proto3" json:"max_wait_duration,omitempty"`
	FailAfterDuration *durationpb.Duration `protobuf:"bytes,13,opt,name=fail_after_duration,json=failAfterDuration,proto3" json:"fail_after_duration,omitempty"`
	WatchPaths        []string             `protobuf:"bytes,14,rep,name=watch_paths,json=watchPaths,proto3" json:"watch_paths,omitempty"`
	// contains filtered or unexported fields
}

func (*Etcd) Descriptor deprecated

func (*Etcd) Descriptor() ([]byte, []int)

Deprecated: Use Etcd.ProtoReflect.Descriptor instead.

func (*Etcd) GetAddresses

func (x *Etcd) GetAddresses() []string

func (*Etcd) GetAutoSyncInterval

func (x *Etcd) GetAutoSyncInterval() *durationpb.Duration

func (*Etcd) GetDialTimeout

func (x *Etcd) GetDialTimeout() *durationpb.Duration

func (*Etcd) GetEnabled

func (x *Etcd) GetEnabled() bool

func (*Etcd) GetFailAfterDuration

func (x *Etcd) GetFailAfterDuration() *durationpb.Duration

func (*Etcd) GetMaxCallRecvMsgSize

func (x *Etcd) GetMaxCallRecvMsgSize() int32

func (*Etcd) GetMaxCallSendMsgSize

func (x *Etcd) GetMaxCallSendMsgSize() int32

func (*Etcd) GetMaxWaitDuration

func (x *Etcd) GetMaxWaitDuration() *durationpb.Duration

func (*Etcd) GetPassword

func (x *Etcd) GetPassword() string

func (*Etcd) GetUsername

func (x *Etcd) GetUsername() string

func (*Etcd) GetWatchPaths

func (x *Etcd) GetWatchPaths() []string

func (*Etcd) ProtoMessage

func (*Etcd) ProtoMessage()

func (*Etcd) ProtoReflect

func (x *Etcd) ProtoReflect() protoreflect.Message

func (*Etcd) Reset

func (x *Etcd) Reset()

func (*Etcd) String

func (x *Etcd) String() string

type EtcdConfig

type EtcdConfig struct {
	Addresses []string
	UserName  string
	Password  string
}

type EtcdKV

type EtcdKV struct {
	Conf EtcdConfig
	*clientv3.Client
	// contains filtered or unexported fields
}

func NewEtcdKV

func NewEtcdKV(conf EtcdConfig, opts ...EtcdKVOption) *EtcdKV

func (*EtcdKV) ApplyOptions

func (o *EtcdKV) ApplyOptions(options ...EtcdKVOption) *EtcdKV

func (*EtcdKV) Close

func (d *EtcdKV) Close() error

func (*EtcdKV) GetKV

func (d *EtcdKV) GetKV(ctx context.Context) (*clientv3.Client, error)

func (*EtcdKV) GetKVUntil

func (d *EtcdKV) GetKVUntil(
	ctx context.Context,
	maxWaitInterval time.Duration,
	failAfter time.Duration,
) (*clientv3.Client, error)

func (*EtcdKV) Lock

func (d *EtcdKV) Lock(ctx context.Context, opts ...EtcdKVOption) error

func (*EtcdKV) TxPipelined

func (d *EtcdKV) TxPipelined(ctx context.Context, cmps []clientv3.Cmp, doOps, elOps []clientv3.Op) error

func (*EtcdKV) Unlock

func (d *EtcdKV) Unlock(ctx context.Context) error

func (*EtcdKV) Watch

func (d *EtcdKV) Watch(ctx context.Context)

type EtcdKVOption

type EtcdKVOption interface {
	// contains filtered or unexported methods
}

A EtcdKVOption sets options.

func WithAutoSyncInterval

func WithAutoSyncInterval(autoSyncInterval time.Duration) EtcdKVOption

func WithDialTimeout

func WithDialTimeout(dialTimeout time.Duration) EtcdKVOption

func WithLockKey

func WithLockKey(key string) EtcdKVOption

func WithLockPrefixPath

func WithLockPrefixPath(prefix string) EtcdKVOption

func WithLockTTL

func WithLockTTL(ttl time.Duration) EtcdKVOption

func WithMaxCallRecvMsgSize

func WithMaxCallRecvMsgSize(msgSize int) EtcdKVOption

func WithMaxCallSendMsgSize

func WithMaxCallSendMsgSize(msgSize int) EtcdKVOption

func WithWatchCreateCallbackFunc

func WithWatchCreateCallbackFunc(f EventCallbackFunc) EtcdKVOption

func WithWatchDeleteCallbackFunc

func WithWatchDeleteCallbackFunc(f EventCallbackFunc) EtcdKVOption

func WithWatchPaths

func WithWatchPaths(paths []string) EtcdKVOption

type EtcdKVOptionFunc

type EtcdKVOptionFunc func(*EtcdKV)

EtcdKVOptionFunc wraps a function that modifies EtcdKV into an implementation of the EtcdKVOption interface.

type EtcdKVOptions

type EtcdKVOptions struct {
	DialTimeout        time.Duration
	MaxCallSendMsgSize int
	MaxCallRecvMsgSize int
	AutoSyncInterval   time.Duration

	LockPrefixPath     string
	LockKey            string
	LockTTL            time.Duration
	WatchPaths         []string
	CreateCallbackFunc EventCallbackFunc
	DeleteCallbackFunc EventCallbackFunc
}

type EventCallbackFunc

type EventCallbackFunc func(ctx context.Context, key, value string)

Jump to

Keyboard shortcuts

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