client

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 31 Imported by: 3

README

Regatta Go client

GoDoc tag Go Version Build Status Coverage Status Go report Contributors License

This repository hosts the code of Regatta client for Go language. For documentation and examples check the godocs page. Additional functionality like Prometheus metrics and OpenTelemetry tracing is provided using plugins.

Example use

package main

import (
	"context"
	"fmt"
	"time"

	client "github.com/jamf/regatta-go"
)

func main() {
	// Create Regatta client
	c, err := client.New(
		client.WithEndpoints("127.0.0.1:8443"),
		client.WithLogger(client.PrintLogger{}),
		client.WithSecureConfig(&client.SecureConfig{
			InsecureSkipVerify: true, // Skip verification of self-signed certificate
		}),
	)
	if err != nil {
		panic(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) // Provide operation timeout
	defer cancel()
	
	put, err := c.Table("regatta-test").Put(ctx, "foo", "bar")
	if err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", put)
}

Contributing

Regatta is in active development and contributors are welcome! Feel free to ask questions and engage in GitHub Discussions!

Documentation

Overview

Package client implements the official Go regatta client.

Create client using `client.New`:

// expect dial time-out on blackhole address
_, err := client.New(client.ConfigSpec{
	Endpoints:   []string{"http://254.0.0.1:12345"},
	DialTimeout: 2 * time.Second,
})

if err == context.DeadlineExceeded {
	// handle errors
}

cli, err := client.New(client.ConfigSpec{
	Endpoints:   []string{"localhost:2379", "localhost:22379", "localhost:32379"},
	DialTimeout: 5 * time.Second,
})
if err != nil {
	// handle error!
}
defer cli.Close()

Make sure to close the client after using it. If the client is not closed, the connection will have leaky goroutines.

To specify a client request timeout, wrap the context with context.WithTimeout:

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
resp, err := kvc.Table("table).Put(ctx, "key", "sample_value")
if err != nil {
    // handle error!
}
// use the response

The Client has internal state, so Clients should be reused instead of created as needed. Clients are safe for concurrent use by multiple goroutines.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAvailableEndpoints = errors.New("regattaclient: no available endpoints")
	ErrOldCluster           = errors.New("regattaclient: old cluster version")
)
View Source
var (
	MetadataRequireLeaderKey    = "has-leader"
	MetadataClientAPIVersionKey = "client-api-version"
	MetadataHasLeader           = "true"
)
View Source
var Version = "unknown"

Functions

func ErrorDesc

func ErrorDesc(err error) string

func GetPrefixRangeEnd

func GetPrefixRangeEnd(prefix string) string

GetPrefixRangeEnd gets the range end of the prefix. 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'.

func IsConnCanceled

func IsConnCanceled(err error) bool

IsConnCanceled returns true, if error is from a closed gRPC connection. ref. https://github.com/grpc/grpc-go/pull/1854

func IsOptsWithFromKey

func IsOptsWithFromKey(opts []OpOption) bool

IsOptsWithFromKey returns true if WithFromKey option is called in the given opts.

func IsOptsWithPrefix

func IsOptsWithPrefix(opts []OpOption) bool

IsOptsWithPrefix returns true if WithPrefix option is called in the given opts.

func WithRequireLeader

func WithRequireLeader(ctx context.Context) context.Context

WithRequireLeader requires client requests to only succeed when the cluster has a leader.

Types

type Client

type Client struct {
	KV
	Cluster
	Tables
	// contains filtered or unexported fields
}

Client provides and manages an regatta client session.

func New

func New(opts ...Option) (*Client, error)

New creates a new regatta client from a given configuration.

func NewFromURL

func NewFromURL(url string, opts ...Option) (*Client, error)

NewFromURL creates a new regatta client from a URL.

func NewFromURLs

func NewFromURLs(urls []string, opts ...Option) (*Client, error)

NewFromURLs creates a new regatta client from URLs.

func (*Client) ActiveConnection

func (c *Client) ActiveConnection() *grpc.ClientConn

ActiveConnection returns the current in-use connection.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client's regatta connections.

func (*Client) Ctx

func (c *Client) Ctx() context.Context

Ctx is a context for "out of band" messages (e.g., for sending "clean up" message when another context is canceled). It is canceled on client Close().

func (*Client) Dial

func (c *Client) Dial(ep string) (*grpc.ClientConn, error)

Dial connects to a single endpoint using the client's config.

func (*Client) Endpoints

func (c *Client) Endpoints() []string

Endpoints lists the registered endpoints for the client.

func (*Client) HandleConn

func (c *Client) HandleConn(ctx context.Context, stats stats.ConnStats)

func (*Client) HandleRPC

func (c *Client) HandleRPC(ctx context.Context, stats stats.RPCStats)

func (*Client) SetEndpoints

func (c *Client) SetEndpoints(eps ...string)

SetEndpoints updates client's endpoints.

func (*Client) SetLogger

func (c *Client) SetLogger(lg Logger) *Client

SetLogger overrides the logger. Does not change grpcLogger, that can be explicitly configured using grpc_zap.ReplaceGrpcLoggerV2(..) method.

func (*Client) Sync

func (c *Client) Sync(ctx context.Context) error

Sync synchronizes client's endpoints with the known endpoints from the regatta membership.

func (*Client) TagConn

func (c *Client) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

func (*Client) TagRPC

func (c *Client) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

type Cluster

type Cluster interface {
	// MemberList lists the current cluster membership.
	MemberList(ctx context.Context) (*MemberListResponse, error)
	// Status gets the status of the endpoint.
	Status(ctx context.Context, endpoint string) (*StatusResponse, error)
}

func NewClusterFromClusterClient

func NewClusterFromClusterClient(remote regattapb.ClusterClient, c *Client) Cluster

type Cmp

type Cmp struct {
	*regattapb.Compare
}

func Compare

func Compare(cmp Cmp, result string, v interface{}) Cmp

func Value

func Value(key string) Cmp

func (Cmp) KeyBytes

func (cmp Cmp) KeyBytes() []byte

KeyBytes returns the byte slice holding with the comparison key.

func (Cmp) ValueBytes

func (cmp Cmp) ValueBytes() []byte

ValueBytes returns the byte slice holding the comparison value, if any.

func (Cmp) WithKeyBytes

func (cmp Cmp) WithKeyBytes(key []byte) Cmp

WithKeyBytes sets the byte slice for the comparison key.

func (Cmp) WithPrefix

func (cmp Cmp) WithPrefix() Cmp

WithPrefix sets the comparison to scan all keys prefixed by the key.

func (Cmp) WithRange

func (cmp Cmp) WithRange(end string) Cmp

WithRange sets the comparison to scan the range [key, end).

func (Cmp) WithValueBytes

func (cmp Cmp) WithValueBytes(v []byte) Cmp

WithValueBytes sets the byte slice for the comparison's value.

type CompareResult

type CompareResult int

type CompareTarget

type CompareTarget int
const (
	CompareVersion CompareTarget = iota
	CompareCreated
	CompareModified
	CompareValue
)

type CreateTableResponse added in v0.4.0

type CreateTableResponse regattapb.CreateTableResponse

func (*CreateTableResponse) String added in v0.4.0

func (resp *CreateTableResponse) String() string

type DeleteResponse

type DeleteResponse struct {
	Header *ResponseHeader `json:"header,omitempty"`
	// deleted is the number of keys deleted by the delete range request.
	Deleted int64 `json:"deleted,omitempty"`
	// if prev_kv is set in the request, the previous key-value pairs will be returned.
	PrevKvs []*KeyValue `json:"prev_kvs,omitempty"`
}

func (*DeleteResponse) OpResponse

func (resp *DeleteResponse) OpResponse() OpResponse

func (*DeleteResponse) String added in v0.0.2

func (resp *DeleteResponse) String() string

type DeleteTableResponse added in v0.4.0

type DeleteTableResponse regattapb.DeleteTableResponse

type FakeClient added in v0.1.3

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

FakeClient provides a fake regatta client. This client is intended to be used only in tests.

func NewFake added in v0.1.3

func NewFake(fakeResponses ...FakeResponse) (*FakeClient, context.CancelFunc)

NewFake creates an instance of FakeClient, including a function for client termination.

func (*FakeClient) Client added in v0.1.3

func (c *FakeClient) Client() *Client

Client returns a new instance of regatta client targeting the fake regatta server.

func (*FakeClient) RecordedRequests added in v0.2.2

func (c *FakeClient) RecordedRequests() []RecordedRequest

type FakeResponse added in v0.1.3

type FakeResponse struct {
	Response OpResponse
	Err      error
}

FakeResponse holds response fields returned by the fake client.

type GetResponse

type GetResponse struct {
	Header *ResponseHeader `json:"header,omitempty"`
	// kvs is the list of key-value pairs matched by the range request.
	// kvs is empty when count is requested.
	Kvs []*KeyValue `json:"kvs,omitempty"`
	// more indicates if there are more keys to return in the requested range.
	More bool `json:"more,omitempty"`
	// count is set to the number of keys within the range when requested.
	Count int64 `json:"count,omitempty"`
}

func (*GetResponse) OpResponse

func (resp *GetResponse) OpResponse() OpResponse

func (*GetResponse) String added in v0.0.2

func (resp *GetResponse) String() string

type Hook

type Hook any

Hook is a hook to be called when something happens in regatta-go.

The base Hook interface is useless, but wherever a hook can occur in kgo, the client checks if your hook implements an appropriate interface. If so, your hook is called.

This allows you to only hook in to behavior you care about, and it allows the client to add more hooks in the future.

All hook interfaces in this package have Hook in the name. Hooks must be safe for concurrent use. It is expected that hooks are fast; if a hook needs to take time, then copy what you need and ensure the hook is async.

type HookClientClosed

type HookClientClosed interface {
	// OnClientClosed is passed the client that has been closed, after
	// all client-internal close cleanup has happened.
	OnClientClosed(*Client)
}

HookClientClosed is called in Close after a client has been closed. This hook can be used to perform final cleanup work.

type HookHandleConn

type HookHandleConn interface {
	OnHandleConn(context.Context, stats.ConnStats)
}

HookHandleConn is called whenever connection is changed (connected/disconnected/errored). the provided stats could be of various types, check implementation of stats.ConnStats interface.

type HookHandleRPC

type HookHandleRPC interface {
	OnHandleRPC(context.Context, stats.RPCStats)
}

HookHandleRPC is called whenever any RPC is made by the client. the provided stats could be of various types, check implementation of stats.RPCStats interface.

type HookKVOpDo added in v0.0.2

type HookKVOpDo interface {
	OnKVCall(context.Context, string, Op, KvDo) (OpResponse, error)
}

type HookNewClient

type HookNewClient interface {
	// OnNewClient is passed the newly initialized client, before any
	// client goroutines are started.
	OnNewClient(*Client)
}

HookNewClient is called in NewClient after a client is initialized. This hook can be used to perform final setup work in your hooks.

type IteratorResponse added in v0.3.0

type IteratorResponse func(yield func(response *GetResponse, err error) bool)

func (IteratorResponse) OpResponse added in v0.3.1

func (resp IteratorResponse) OpResponse() OpResponse

type KV

type KV interface {
	// Put puts a key-value pair into regatta.
	// Note that key,value can be plain bytes array and string is
	// an immutable representation of that bytes array.
	// To get a string of bytes, do string([]byte{0x10, 0x20}).
	Put(ctx context.Context, table, key, val string, opts ...OpOption) (*PutResponse, error)

	// Get retrieves keys.
	// By default, Get will return the value for "key", if any.
	// When passed WithRange(end), Get will return the keys in the range [key, end).
	// When passed WithFromKey(), Get returns keys greater than or equal to key.
	// When passed key "" and WithFromKey(), Get returns all keys.
	// When passed WithRev(rev) with rev > 0, Get retrieves keys at the given revision;
	// if the required revision is compacted, the request will fail with ErrCompacted .
	// When passed WithLimit(limit), the number of returned keys is bounded by limit.
	// When passed WithSort(), the keys will be sorted.
	// Note that a single response is limited by a max size of ~4MiB. If more keys in the range exists the GetResponse.More will be set to true.
	Get(ctx context.Context, table, key string, opts ...OpOption) (*GetResponse, error)

	// Iterate retrieves keys in iterator fashion, use this if you expect that the dataset returned will be larger than 4MiB.
	// Iterator runs until exhaustion or until the callback func returns false.
	// By default, Iterate will return the value for "key", if any.
	// When passed WithRange(end), Iterate will return the keys in the range [key, end).
	// When passed WithFromKey(), Iterate returns keys greater than or equal to key.
	// When passed key "" and WithFromKey(), Iterate returns all keys.
	// When passed WithRev(rev) with rev > 0, Iterate retrieves keys at the given revision;
	// if the required revision is compacted, the request will fail with ErrCompacted .
	// When passed WithLimit(limit), the number of returned keys is bounded by limit.
	// When passed WithSort(), the keys will be sorted.
	Iterate(ctx context.Context, table, key string, opts ...OpOption) (IteratorResponse, error)

	// Delete deletes a key, or optionally using WithRange(end), [key, end).
	Delete(ctx context.Context, table, key string, opts ...OpOption) (*DeleteResponse, error)

	// Do apply a single Op on KV without a transaction.
	// Do is useful when creating arbitrary operations to be issued at a
	// later time; the user can range over the operations, calling Do to
	// execute them. Get/Put/Delete, on the other hand, are best suited
	// for when the operation should be issued at the time of declaration.
	Do(ctx context.Context, table string, op Op) (OpResponse, error)

	// Table is a convenience function that provides requests scoped to a single table.
	Table(name string) Table

	// Txn creates a transaction.
	Txn(ctx context.Context, table string) Txn
}

type KeyValue

type KeyValue regattapb.KeyValue

type KvDo added in v0.0.2

type KvDo func(context.Context, string, Op) (OpResponse, error)

type ListTablesResponse added in v0.4.0

type ListTablesResponse struct {
	Tables []TableInfo
}

func (*ListTablesResponse) String added in v0.4.0

func (resp *ListTablesResponse) String() string

type Logger

type Logger interface {
	Infof(string, ...any)
	Debugf(string, ...any)
	Warnf(string, ...any)
	Errorf(string, ...any)
}

type Member

type Member regattapb.Member

type MemberListResponse

type MemberListResponse regattapb.MemberListResponse

type NoOpLogger added in v0.0.3

type NoOpLogger struct{}

func (NoOpLogger) Debugf added in v0.0.3

func (n NoOpLogger) Debugf(s string, a ...any)

func (NoOpLogger) Errorf added in v0.0.3

func (n NoOpLogger) Errorf(s string, a ...any)

func (NoOpLogger) Infof added in v0.0.3

func (n NoOpLogger) Infof(s string, a ...any)

func (NoOpLogger) Warnf added in v0.0.3

func (n NoOpLogger) Warnf(s string, a ...any)

type Op

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

Op represents an Operation that kv can execute.

func NewOp

func NewOp() *Op

func OpDelete

func OpDelete(key string, opts ...OpOption) Op

OpDelete returns "delete" operation based on given key and operation options.

func OpGet

func OpGet(key string, opts ...OpOption) Op

OpGet returns "get" operation based on given key and operation options.

func OpIterate added in v0.3.0

func OpIterate(key string, opts ...OpOption) Op

func OpPut

func OpPut(key, val string, opts ...OpOption) Op

OpPut returns "put" operation based on given key-value and operation options.

func OpTxn

func OpTxn(cmps []Cmp, thenOps []Op, elseOps []Op) Op

OpTxn returns "txn" operation based on given transaction conditions.

func (*Op) IsCountOnly

func (op *Op) IsCountOnly() bool

IsCountOnly returns whether countOnly is set.

func (*Op) IsDelete

func (op *Op) IsDelete() bool

IsDelete returns true if the operation is a Delete.

func (*Op) IsGet

func (op *Op) IsGet() bool

IsGet returns true if the operation is a Get.

func (*Op) IsIterate added in v0.3.0

func (op *Op) IsIterate() bool

IsIterate returns true if the operation is Iterate.

func (*Op) IsKeysOnly

func (op *Op) IsKeysOnly() bool

IsKeysOnly returns whether keysOnly is set.

func (*Op) IsPut

func (op *Op) IsPut() bool

IsPut returns true if the operation is a Put.

func (*Op) IsSerializable

func (op *Op) IsSerializable() bool

IsSerializable returns true if the serializable field is true.

func (*Op) IsTxn

func (op *Op) IsTxn() bool

IsTxn returns true if the "Op" type is transaction.

func (*Op) KeyBytes

func (op *Op) KeyBytes() []byte

KeyBytes returns the byte slice holding the Op's key.

func (*Op) RangeBytes

func (op *Op) RangeBytes() []byte

RangeBytes returns the byte slice holding with the Op's range end, if any.

func (*Op) Rev

func (op *Op) Rev() int64

Rev returns the requested revision, if any.

func (*Op) Txn

func (op *Op) Txn() ([]Cmp, []Op, []Op)

Txn returns the comparison(if) operations, "then" operations, and "else" operations.

func (*Op) ValueBytes

func (op *Op) ValueBytes() []byte

ValueBytes returns the byte slice holding the Op's value, if any.

func (*Op) WithKeyBytes

func (op *Op) WithKeyBytes(key []byte)

WithKeyBytes sets the byte slice for the Op's key.

func (*Op) WithRangeBytes

func (op *Op) WithRangeBytes(end []byte)

WithRangeBytes sets the byte slice for the Op's range end.

func (*Op) WithValueBytes

func (op *Op) WithValueBytes(v []byte)

WithValueBytes sets the byte slice for the Op's value.

type OpOption

type OpOption func(*Op)

OpOption configures Operations like Get, Put, Delete.

func WithCount added in v0.1.5

func WithCount() OpOption

WithCount makes the 'Delete' request return also count of deleted key-value pairs.

func WithCountOnly

func WithCountOnly() OpOption

WithCountOnly makes the 'Get' request return only the count of keys.

func WithFromKey

func WithFromKey() OpOption

WithFromKey specifies the range of 'Get', 'Delete', 'Watch' requests to be equal or greater than the key in the argument.

func WithKeysOnly

func WithKeysOnly() OpOption

WithKeysOnly makes the 'Get' request return only the keys and the corresponding values will be omitted.

func WithLimit

func WithLimit(n int64) OpOption

WithLimit limits the number of results to return from 'Get' request. If WithLimit is given a 0 limit, it is treated as no limit.

func WithPrefix

func WithPrefix() OpOption

WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate on the keys with matching prefix. For example, 'Get(foo, WithPrefix())' can return 'foo1', 'foo2', and so on.

func WithPrevKV

func WithPrevKV() OpOption

WithPrevKV gets the previous key-value pair before the event happens. If the previous KV is already compacted, nothing will be returned.

func WithRange

func WithRange(endKey string) OpOption

WithRange specifies the range of 'Get', 'Delete', 'Watch' requests. For example, 'Get' requests with 'WithRange(end)' returns the keys in the range [key, end). endKey must be lexicographically greater than start key.

func WithRev

func WithRev(rev int64) OpOption

WithRev specifies the store revision for 'Get' request. Or the start revision of 'Watch' request.

func WithSerializable

func WithSerializable() OpOption

WithSerializable makes 'Get' request serializable. By default, it's linearizable. Serializable requests are better for lower latency requirement.

type OpResponse

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

func (OpResponse) Del

func (op OpResponse) Del() *DeleteResponse

func (OpResponse) Get

func (op OpResponse) Get() *GetResponse

func (OpResponse) Iterate added in v0.3.0

func (op OpResponse) Iterate() IteratorResponse

func (OpResponse) Put

func (op OpResponse) Put() *PutResponse

func (OpResponse) Txn

func (op OpResponse) Txn() *TxnResponse

type Option

type Option func(config *config)

Option is a function type that can be passed as argument to New to configure client.

func WithAutoSyncInterval added in v0.0.3

func WithAutoSyncInterval(interval time.Duration) Option

WithAutoSyncInterval is the interval to update endpoints with its latest members. 0 disables auto-sync. By default, auto-sync is disabled.

func WithBlock added in v0.1.0

func WithBlock() Option

WithBlock returns a DialOption which makes callers of Dial block until the underlying connection is up. Without this, Dial returns immediately and connecting the server happens in background. Use of this feature is not recommended. For more information, please see: https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md

func WithDialOptions added in v0.0.3

func WithDialOptions(dial ...grpc.DialOption) Option

WithDialOptions sets the list of dial options for the grpc client (e.g., for interceptors). For example, pass "grpc.WithBlock()" to block until the underlying connection is up. Without this, Dial returns immediately and connecting the server happens in background.

func WithDialTimeout added in v0.1.0

func WithDialTimeout(t time.Duration) Option

WithDialTimeout sets the dial timeout.

func WithEndpoints added in v0.0.3

func WithEndpoints(endpoints ...string) Option

WithEndpoints sets the list of seed URLs.

func WithHooks added in v0.0.3

func WithHooks(hooks ...Hook) Option

WithHooks sets plugin hooks, check the plugin directory for available plugin modules.

func WithKeepalive added in v0.1.0

func WithKeepalive(keepaliveTime, keepaliveTimeout time.Duration) Option

WithKeepalive sets the keepalive protocol timeouts, keepaliveTime is the time after which client pings the server to see if transport is alive. keepaliveTimeout is the time that the client waits for a response for the keep-alive probe. If the response is not received in this time, the connection is closed.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger sets client-side logger. Defaults to NOOp logger.

func WithMaxCallRecvMsgSize added in v0.0.3

func WithMaxCallRecvMsgSize(max int) Option

WithMaxCallRecvMsgSize sets 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. ("--api.max-recv-bytes" flag to regatta).

func WithMaxCallSendMsgSize added in v0.0.3

func WithMaxCallSendMsgSize(max int) Option

WithMaxCallSendMsgSize sets the client-side request send limit in bytes. If 0, it defaults to 2.0 MiB (2 * 1024 * 1024). Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit. ("--api.max-send-bytes" flag to regatta or "embed.Config.MaxRequestBytes").

func WithRejectOldCluster added in v0.0.3

func WithRejectOldCluster(roc bool) Option

WithRejectOldCluster set will refuse to create a client against an outdated cluster.

func WithReturnConnectionError added in v0.1.0

func WithReturnConnectionError() Option

WithReturnConnectionError returns a DialOption which makes the client connection return a string containing both the last connection error that occurred and the context.DeadlineExceeded error. Implies WithBlock().

func WithSecureConfig added in v0.0.3

func WithSecureConfig(sc *SecureConfig) Option

WithSecureConfig sets the TLS and related configs.

type PrintLogger

type PrintLogger struct{}

func (PrintLogger) Debugf

func (p PrintLogger) Debugf(s string, a ...any)

func (PrintLogger) Errorf

func (p PrintLogger) Errorf(s string, a ...any)

func (PrintLogger) Infof

func (p PrintLogger) Infof(s string, a ...any)

func (PrintLogger) Warnf

func (p PrintLogger) Warnf(s string, a ...any)

type PutResponse

type PutResponse struct {
	Header *ResponseHeader `json:"header,omitempty"`
	// if prev_kv is set in the request, the previous key-value pair will be returned.
	PrevKv *KeyValue `json:"prev_kv,omitempty"`
}

func (*PutResponse) OpResponse

func (resp *PutResponse) OpResponse() OpResponse

func (*PutResponse) String added in v0.0.2

func (resp *PutResponse) String() string

type RecordedRequest added in v0.2.2

type RecordedRequest struct {
	Table   string
	Request Op
}

RecordedRequest holds request fields recorded by the fake client.

type ResponseHeader

type ResponseHeader regattapb.ResponseHeader

type ResponseOp

type ResponseOp struct {
	*regattapb.ResponseOp
}

func (*ResponseOp) GetResponseDeleteRange added in v0.3.0

func (x *ResponseOp) GetResponseDeleteRange() *ResponseOpDeleteRange

func (*ResponseOp) GetResponsePut added in v0.3.0

func (x *ResponseOp) GetResponsePut() *ResponseOpPut

func (*ResponseOp) GetResponseRange added in v0.3.0

func (x *ResponseOp) GetResponseRange() *ResponseOpRange

type ResponseOpDeleteRange added in v0.3.0

type ResponseOpDeleteRange regattapb.ResponseOp_DeleteRange

type ResponseOpPut added in v0.3.0

type ResponseOpPut regattapb.ResponseOp_Put

type ResponseOpRange added in v0.3.0

type ResponseOpRange regattapb.ResponseOp_Range

type SecureConfig

type SecureConfig struct {
	Cert       string `json:"cert"`
	Key        string `json:"key"`
	Cacert     string `json:"cacert"`
	ServerName string `json:"server-name"`

	InsecureTransport  bool `json:"insecure-transport"`
	InsecureSkipVerify bool `json:"insecure-skip-tls-verify"`
}

type StatusResponse

type StatusResponse struct {
	// Id is the member ID of this member.
	Id string
	// Version is the semver version used by the responding member.
	Version string
	// Info is the additional server info.
	Info string
	// Tables is a status of tables of the responding member.
	Tables map[string]*TableStatus
	// Errors contains alarm/health information and status.
	Errors []string
	// Config contains the member configuration.
	Config map[string]any
}

StatusResponse represents response from Status API.

type TLSInfo

type TLSInfo struct {
	// CertFile is the _server_ cert, it will also be used as a _client_ certificate if ClientCertFile is empty
	CertFile string
	// KeyFile is the key for the CertFile
	KeyFile string
	// ClientCertFile is a _client_ cert for initiating connections when ClientCertAuth is defined. If ClientCertAuth
	// is true but this value is empty, the CertFile will be used instead.
	ClientCertFile string
	// ClientKeyFile is the key for the ClientCertFile
	ClientKeyFile string

	TrustedCAFile       string
	ClientCertAuth      bool
	CRLFile             string
	InsecureSkipVerify  bool
	SkipClientSANVerify bool

	// ServerName ensures the cert matches the given host in case of discovery / virtual hosting
	ServerName string

	// HandshakeFailure is optionally called when a connection fails to handshake. The
	// connection will be closed immediately afterwards.
	HandshakeFailure func(*tls.Conn, error)

	// CipherSuites is a list of supported cipher suites.
	// If empty, Go auto-populates it by default.
	// Note that cipher suites are prioritized in the given order.
	CipherSuites []uint16

	// AllowedCN is a CN which must be provided by a client.
	AllowedCN string

	// AllowedHostname is an IP address or hostname that must match the TLS
	// certificate provided by a client.
	AllowedHostname string

	// Logger logs TLS errors.
	// If nil, all logs are discarded.
	Logger Logger

	// EmptyCN indicates that the cert must have empty CN.
	// If true, ClientConfig() will return an error for a cert with non empty CN.
	EmptyCN bool
	// contains filtered or unexported fields
}

func (TLSInfo) ClientConfig

func (info TLSInfo) ClientConfig() (*tls.Config, error)

ClientConfig generates a tls.Config object for use by an HTTP client.

func (TLSInfo) Empty

func (info TLSInfo) Empty() bool

func (TLSInfo) String

func (info TLSInfo) String() string

type Table

type Table interface {
	// Put puts a key-value pair into regatta.
	// Note that key,value can be plain bytes array and string is
	// an immutable representation of that bytes array.
	// To get a string of bytes, do string([]byte{0x10, 0x20}).
	Put(ctx context.Context, key, val string, opts ...OpOption) (*PutResponse, error)

	// Get retrieves keys.
	// By default, Get will return the value for "key", if any.
	// When passed WithRange(end), Get will return the keys in the range [key, end).
	// When passed WithFromKey(), Get returns keys greater than or equal to key.
	// When passed WithRev(rev) with rev > 0, Get retrieves keys at the given revision;
	// if the required revision is compacted, the request will fail with ErrCompacted .
	// When passed WithLimit(limit), the number of returned keys is bounded by limit.
	// When passed WithSort(), the keys will be sorted.
	Get(ctx context.Context, key string, opts ...OpOption) (*GetResponse, error)

	// Iterate retrieves keys in iterator fashion, use this if you expect that the dataset returned will be larger than 4MiB.
	// Iterator runs until exhaustion or until the callback func returns false.
	// By default, Iterate will return the value for "key", if any.
	// When passed WithRange(end), Iterate will return the keys in the range [key, end).
	// When passed WithFromKey(), Iterate returns keys greater than or equal to key.
	// When passed key "" and WithFromKey(), Iterate returns all keys.
	// When passed WithRev(rev) with rev > 0, Iterate retrieves keys at the given revision;
	// if the required revision is compacted, the request will fail with ErrCompacted .
	// When passed WithLimit(limit), the number of returned keys is bounded by limit.
	// When passed WithSort(), the keys will be sorted.
	Iterate(ctx context.Context, key string, opts ...OpOption) (IteratorResponse, error)

	// Delete deletes a key, or optionally using WithRange(end), [key, end).
	Delete(ctx context.Context, key string, opts ...OpOption) (*DeleteResponse, error)

	// Txn creates a transaction.
	Txn(ctx context.Context) Txn
}

type TableInfo added in v0.4.0

type TableInfo struct {
	ID     string
	Name   string
	Config map[string]any
}

type TableStatus added in v0.2.1

type TableStatus regattapb.TableStatus

type Tables added in v0.4.0

type Tables interface {
	// CreateTable creates table with specified name.
	CreateTable(ctx context.Context, name string) (*CreateTableResponse, error)
	// DeleteTable gets the status of the endpoint.
	DeleteTable(ctx context.Context, name string) (*DeleteTableResponse, error)
	// ListTables lists all currently registered tables.
	ListTables(ctx context.Context) (*ListTablesResponse, error)
}

func NewTablesFromTablesClient added in v0.4.0

func NewTablesFromTablesClient(remote regattapb.TablesClient, c *Client) Tables

type Txn

type Txn interface {
	// If takes a list of comparison. If all comparisons passed in succeed,
	// the operations passed into Then() will be executed. Or the operations
	// passed into Else() will be executed.
	If(cs ...Cmp) Txn

	// Then takes a list of operations. The Ops list will be executed, if the
	// comparisons passed in If() succeed.
	Then(ops ...Op) Txn

	// Else takes a list of operations. The Ops list will be executed, if the
	// comparisons passed in If() fail.
	Else(ops ...Op) Txn

	// Commit tries to commit the transaction.
	Commit() (*TxnResponse, error)
}

type TxnResponse

type TxnResponse struct {
	Header *ResponseHeader `json:"header,omitempty"`
	// succeeded is set to true if the compare evaluated to true or false otherwise.
	Succeeded bool `json:"succeeded,omitempty"`
	// responses is a list of responses corresponding to the results from applying
	// success if succeeded is true or failure if succeeded is false.
	Responses []*ResponseOp `json:"responses,omitempty"`
}

func (*TxnResponse) OpResponse

func (resp *TxnResponse) OpResponse() OpResponse

func (*TxnResponse) String added in v0.0.2

func (resp *TxnResponse) String() string

Directories

Path Synopsis
internal
plugin
rlogrus Module
rotel Module
rprom Module
rzap Module

Jump to

Keyboard shortcuts

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