Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Etcd
- func (e *Etcd) Delete(ctx context.Context, key string) error
- func (e *Etcd) Get(ctx context.Context, key string, opts ...kvstore.GetOpt) ([]*kvstore.Record, error)
- func (e *Etcd) GetMetadataLeaseID(record *kvstore.Record) (clientv3.LeaseID, error)
- func (e *Etcd) HasInitializer() bool
- func (e *Etcd) Init(opts ...kvstore.Option) error
- func (e *Etcd) Initializer() component.Initializer
- func (e *Etcd) LeaseID(ctx context.Context, record *kvstore.Record) (clientv3.LeaseID, error)
- func (e *Etcd) Put(ctx context.Context, record *kvstore.Record, opts ...kvstore.SetOpt) (*kvstore.Record, error)
- func (e *Etcd) RenewLease(ctx context.Context, leaseID clientv3.LeaseID) error
- func (e *Etcd) String() string
- func (e *Etcd) Subscribe(ctx context.Context, key string, handler kvstore.SubscribeHandler, ...) error
- func (e *Etcd) Txn(ctx context.Context, handler kvstore.TxnHandler) error
- func (e *Etcd) Unsubscribe(ctx context.Context, key string) error
- type Initializer
Constants ¶
const ( // KEY_LEASE_ID points to the lease ID in the etcd record metadata KEY_LEASE_ID = "lease_id" // KEY_COUNT points to the count in the etcd record metadata KEY_COUNT = "count" // KEY_HEADER points to the header in the etcd record metadata KEY_HEADER = "header" // KEY_MORE points to the more boolean var in the etcd record metadata KEY_MORE = "more" // KEY_REVISION points to the revision in the etcd record metadata KEY_REVISION = "revision" // KEY_VERSION points to the version in the etcd record metadata KEY_VERSION = "version" )
Variables ¶
var ( // ErrInvalidLeaseID returned when the leaseID provided is invalid ErrInvalidLeaseID = errors.New("invalid etcd leaseID passed") // ErrNoResults returned when no results are found ErrNoResults = errors.New("no results found for the given key") // ErrCreatingEtcdClient returned when creating etcd clientv3 fails ErrCreatingEtcdClient = errors.New("error creating kvstore etcd client") // ErrInvalidWatchOption returned when the watch option sent to the // subscribe function is invalid ErrInvalidWatchOption = errors.New("invalid etcd watch option") // ErrInvalidGetOption returned when the get option provided is not valid ErrInvalidGetOption = errors.New("invalid etcd GET() option") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Endpoints is a comma separated list of etcd URLs Endpoints string `env:"KVSTORE_ETCD_ENDPOINTS"` // DialTimeout is the timeout for failing to establish a connection DialTimeout time.Duration `env:"KVSTORE_ETCD_DIALTIMEOUT,omitempty"` // Username is a username for authentication Username string `env:"KVSTORE_ETCD_USERNAME,omitempty"` // Password is the password for authentication Password string `env:"KVSTORE_ETCD_PASSWORD,omitempty"` }
Config holds the etcd configuration
func NewConfig ¶
func NewConfig() *Config
NewConfig returns the parsed config for jetstream from env
func (*Config) GetEndpoints ¶
GetEndpoints return the etcd server endpoints
func (*Config) UnmarshalEnv ¶
UnmarshalEnv env.EnvSet to Config
type Etcd ¶
type Etcd struct { Client *clientv3.Client Config *Config // contains filtered or unexported fields }
Etcd holds our etcd instance
func NewEtcd ¶
func NewEtcd() *Etcd
NewEtcd returns a new instance of etcd with etcd client and config
func (*Etcd) Get ¶
func (e *Etcd) Get(ctx context.Context, key string, opts ...kvstore.GetOpt) ([]*kvstore.Record, error)
Get a record by it's key
func (*Etcd) GetMetadataLeaseID ¶
GetMetadataLeaseID returns the leaseID from the record metadata
func (*Etcd) HasInitializer ¶
func (*Etcd) Initializer ¶
func (e *Etcd) Initializer() component.Initializer
func (*Etcd) LeaseID ¶
LeaseID returns the leaseID (if any) to be used by the record If exists, it renews and returns the "lease_id" set in the record metadata If record expiry is set, then it creates a new leaseID and returns it. If it's none of the above, then it returns 0
func (*Etcd) Put ¶
func (e *Etcd) Put(ctx context.Context, record *kvstore.Record, opts ...kvstore.SetOpt) (*kvstore.Record, error)
Put adds the record into the store Get the lease if lease_id is defined in the record metadata, or create new lease if expiry is defined Renew lease using the lease_id in the record metadata, added/used by LeaseID(...) Add the record to the store with the lease_id
func (*Etcd) RenewLease ¶
RenewLease renews the lease with the given leaseID This renews lease if the lease is valid and not 0
func (*Etcd) Subscribe ¶
func (e *Etcd) Subscribe( ctx context.Context, key string, handler kvstore.SubscribeHandler, opts ...kvstore.SubscribeOpt, ) error
Subscribe to the changes made to the given key
type Initializer ¶
type Initializer struct {
// contains filtered or unexported fields
}
func NewInitializer ¶
func NewInitializer(e *Etcd) *Initializer
NewInitializer returns a new JetStream Initialiazer
func (*Initializer) AddDependency ¶
func (i *Initializer) AddDependency(dep interface{}) error
AddDependency adds necessary service components as dependencies
func (*Initializer) CanRun ¶
func (i *Initializer) CanRun() bool
CanRun returns true if the component has anything to Run
func (*Initializer) CanStop ¶
func (i *Initializer) CanStop() bool
CanRun returns true if the component has anything to Run
func (*Initializer) Dependencies ¶
func (i *Initializer) Dependencies() []string
Dependencies returns the string names of service components that are required as dependencies for this component