Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (client *Client) Close() error
- func (client *Client) Delete(ctx context.Context, key string) error
- func (client *Client) Exists(ctx context.Context, key string) (bool, error)
- func (client *Client) Get(ctx context.Context, key string) (*Entry, error)
- func (client *Client) GetAny(ctx context.Context, key string, codec Codec) (any, error)
- func (client *Client) GetProto(ctx context.Context, key string, dst proto.Message) error
- func (client *Client) GetString(ctx context.Context, key string) (string, error)
- func (client *Client) List(ctx context.Context) ([]*Entry, error)
- func (client *Client) Put(ctx context.Context, entry *Entry, expiration time.Duration) error
- func (client *Client) PutAny(ctx context.Context, key string, value any, expiration time.Duration, ...) error
- func (client *Client) PutProto(ctx context.Context, key string, value proto.Message, expiration time.Duration) error
- func (client *Client) PutString(ctx context.Context, key string, value string, expiration time.Duration) error
- type Codec
- type Config
- func (config *Config) Validate() error
- func (config *Config) WithCleanerJobInterval(interval time.Duration) *Config
- func (config *Config) WithDiscoveryPort(port uint16) *Config
- func (config *Config) WithDiscoveryProvider(provider discovery.Provider) *Config
- func (config *Config) WithEncryption(cookie string, secretKeys []string) *Config
- func (config *Config) WithHost(host string) *Config
- func (config *Config) WithJoinRetryInterval(interval time.Duration) *Config
- func (config *Config) WithLogger(logger log.Logger) *Config
- func (config *Config) WithMaxJoinAttempts(max int) *Config
- func (config *Config) WithPort(port uint16) *Config
- func (config *Config) WithReadTimeout(timeout time.Duration) *Config
- func (config *Config) WithShutdownTimeout(timeout time.Duration) *Config
- func (config *Config) WithSyncInterval(interval time.Duration) *Config
- func (config *Config) WithTLS(tlConfig *tls.Config) *Config
- type Entry
- type Event
- type EventType
- type Member
- type Node
- func (node *Node) Client() *Client
- func (node *Node) Delete(ctx context.Context, request *connect.Request[internalpb.DeleteRequest]) (*connect.Response[internalpb.DeleteResponse], error)
- func (node *Node) Events() <-chan *Event
- func (node *Node) Get(ctx context.Context, request *connect.Request[internalpb.GetRequest]) (*connect.Response[internalpb.GetResponse], error)
- func (node *Node) HostPort() string
- func (node *Node) KeyExists(ctx context.Context, request *connect.Request[internalpb.KeyExistsRequest]) (*connect.Response[internalpb.KeyExistResponse], error)
- func (node *Node) Leader() (*Member, error)
- func (node *Node) List(ctx context.Context, request *connect.Request[internalpb.ListRequest]) (*connect.Response[internalpb.ListResponse], error)
- func (node *Node) Peers() ([]*Member, error)
- func (node *Node) Put(ctx context.Context, request *connect.Request[internalpb.PutRequest]) (*connect.Response[internalpb.PutResponse], error)
- func (node *Node) Start(ctx context.Context) error
- func (node *Node) Stop(ctx context.Context) error
- func (node *Node) Whoami() *Member
Constants ¶
const ( // NoExpiration is used to state there is no expiration NoExpiration time.Duration = -1 )
Variables ¶
var ( // ErrNodeNotStarted is returned when the cluster has not started ErrNodeNotStarted = errors.New("cluster node not started") // ErrKeyNotFound is return when the given key value is not found in the cluster ErrKeyNotFound = errors.New("key not found") ErrClientNotConnected = errors.New("cluster client not connected") )
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.1.1
type Client struct {
// contains filtered or unexported fields
}
Client defines the cluster client This client can connect to any Go-KV cluster node and retrieve data from other of the cluster.
func NewClient ¶ added in v0.1.1
NewClient creates an instance of the cluster Client host and port are a Go-KV cluster node host and port
func (*Client) GetAny ¶ added in v0.1.1
GetAny retrieves the value of the given from the cluster Prior to calling this method one must set a string as the value of the key
func (*Client) GetProto ¶ added in v0.1.1
GetProto retrieves the value of the given from the cluster as protocol buffer message Prior to calling this method one must set a proto message as the value of the key
func (*Client) GetString ¶ added in v0.1.1
GetString retrieves the value of the given from the cluster as a string Prior to calling this method one must set a string as the value of the key
func (*Client) PutAny ¶ added in v0.1.1
func (client *Client) PutAny(ctx context.Context, key string, value any, expiration time.Duration, codec Codec) error
PutAny distributes the key/value pair in the cluster. A binary encoder is required to properly encode the value.
type Codec ¶ added in v0.1.1
type Codec interface {
// Encode encodes the receiver into a binary form and returns the result.
Encode(any) ([]byte, error)
// Decode decodes a binary message
Decode([]byte) (any, error)
}
Codec will be implemented to encode and decode message
type Config ¶ added in v0.1.1
type Config struct {
// contains filtered or unexported fields
}
Config defines the cluster config
func NewConfig ¶ added in v0.1.1
func NewConfig() *Config
NewConfig creates an instance of Config with the required default values
func (*Config) WithCleanerJobInterval ¶ added in v0.1.1
WithCleanerJobInterval sets the Node cleaning job interval This helps remove expired entries on the localState of the given node
func (*Config) WithDiscoveryPort ¶ added in v0.1.1
WithDiscoveryPort sets the discovery port
func (*Config) WithDiscoveryProvider ¶ added in v0.1.1
WithDiscoveryProvider sets the discovery provider
func (*Config) WithEncryption ¶ added in v0.1.1
WithEncryption defines the cookie and the secret keys cookie is a set of bytes to use as authentication label This has to be the same within the cluster to ensure smooth GCM authenticated data reference: https://en.wikipedia.org/wiki/Galois/Counter_Mode
A list of base64 encoded keys. Each key should be either 16, 24, or 32 bytes when decoded to select AES-128, AES-192, or AES-256 respectively. The first key in the list will be used for encrypting outbound messages. All keys are attempted when decrypting gossip, which allows for rotations. These keys should be the same for all nodes in the cluster
func (*Config) WithJoinRetryInterval ¶ added in v0.1.1
WithJoinRetryInterval sets the join retry interval
func (*Config) WithLogger ¶ added in v0.1.1
WithLogger sets the logger
func (*Config) WithMaxJoinAttempts ¶ added in v0.1.1
WithMaxJoinAttempts sets the max join attempts
func (*Config) WithReadTimeout ¶ added in v0.1.1
WithReadTimeout sets the Node read timeout. This timeout specifies the timeout of a data retrieval The read timeout should be either greater or equal to syncInterval
func (*Config) WithShutdownTimeout ¶ added in v0.1.1
WithShutdownTimeout sets the timeout
func (*Config) WithSyncInterval ¶ added in v0.1.1
WithSyncInterval sets the cluster synchronization interval. This is the interval between complete states synchronization between nodes. Complete states synchronization are done with a single node over TCP and are quite expensive relative to standard gossiped messages. Setting this interval lower (more frequent) will increase convergence speeds across larger clusters at the expense of increased bandwidth usage.
func (*Config) WithTLS ¶ added in v0.2.0
WithTLS configures TLS settings for both the Server and Client. Ensure that both the Server and Client are configured with the same root Certificate Authority (CA) to enable successful handshake and mutual authentication.
In cluster mode, all nodes must share the same root CA to establish secure communication and complete handshakes successfully.
type Entry ¶ added in v0.1.1
type Entry struct {
// Key represents the key
Key string
// Value represents the value
Value []byte
}
Entry represents the key/value pair
type Member ¶ added in v0.1.1
Member specifies the cluster member
func (*Member) DiscoveryAddress ¶ added in v0.1.1
DiscoveryAddress returns the member discoveryAddress
type Node ¶ added in v0.1.1
type Node struct {
internalpbconnect.UnimplementedKVServiceHandler
// contains filtered or unexported fields
}
Node defines the cluster node
func (*Node) Delete ¶ added in v0.1.1
func (node *Node) Delete(ctx context.Context, request *connect.Request[internalpb.DeleteRequest]) (*connect.Response[internalpb.DeleteResponse], error)
Delete is used to remove a key/value pair from a cluster of nodes nolint
func (*Node) Get ¶ added in v0.1.1
func (node *Node) Get(ctx context.Context, request *connect.Request[internalpb.GetRequest]) (*connect.Response[internalpb.GetResponse], error)
Get is used to retrieve a key/value pair in a cluster of nodes
func (*Node) KeyExists ¶ added in v0.1.1
func (node *Node) KeyExists(ctx context.Context, request *connect.Request[internalpb.KeyExistsRequest]) (*connect.Response[internalpb.KeyExistResponse], error)
KeyExists is used to check the existence of a given key in the cluster nolint
func (*Node) Leader ¶ added in v0.1.1
Leader returns the eldest member of the cluster Leadership here is based upon node time creation
func (*Node) List ¶ added in v0.1.1
func (node *Node) List(ctx context.Context, request *connect.Request[internalpb.ListRequest]) (*connect.Response[internalpb.ListResponse], error)
List returns the list of all entries at a given point in time nolint
func (*Node) Put ¶ added in v0.1.1
func (node *Node) Put(ctx context.Context, request *connect.Request[internalpb.PutRequest]) (*connect.Response[internalpb.PutResponse], error)
Put is used to distribute a key/value pair across a cluster of nodes nolint