srv

package
v0.0.0-...-a76a3ae Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package srv defines the database server. It implements the gRPC server and is responsible for GET, PUT, DEL and WATCH operations on the database. The database is internally powered by bboltDB (https://github.com/etcd-io/bbolt).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is returned when the specified key does not exist
	// in the database.
	ErrKeyNotFound = errors.New("key not found")
	// ErrNoKeysMatchRegex is returned when none of the keys the the
	// database match the given regex.
	ErrNoKeysMatchRegex = errors.New("no keys match the given regex")
)

Functions

This section is empty.

Types

type OptFunc

type OptFunc func(*opts) error

func WithDBPath

func WithDBPath(path string) OptFunc

WithDBPath sets the path to the database file. It throws an error if the specified file is a directory or not writable.

Default: ./data.db

func WithDebug

func WithDebug() OptFunc

WithDebug enables debug logs.

Default: disabled

func WithEventQueueSize

func WithEventQueueSize(size uint) OptFunc

WithEventQueueSize sets the event queue size used by the watcher to notify subscribers about events in their occurrence order.

Default size: 10

func WithJSONLogger

func WithJSONLogger() OptFunc

WithJSONLogger configures logger to use JSON.

Default: disabled

func WithPort

func WithPort(port uint16) OptFunc

WithPort sets the port for the database server. Ensure that the chosen port is available and not in use.

Default: 23023

func WithReflection

func WithReflection() OptFunc

WithReflection enables gRPC reflection

Default: disabled

func WithWatcherPingInterval

func WithWatcherPingInterval(interval time.Duration) OptFunc

WithWatcherPingInterval sets the interval between two keepalive pings for the watcher. Keepalive messages are periodically sent to maintain the watcher's connection. Adjust this value if you encounter connection issues.

Default: 10s

type Srv

type Srv struct {
	pb.UnimplementedApiServer
	// contains filtered or unexported fields
}

Srv implements the gRPC API server and performs database operations on request.

func New

func New(optfns ...OptFunc) (*Srv, error)

New creates a new database server from the given options.

func (*Srv) Backup

func (s *Srv) Backup(in *pb.ChunkSize, stream pb.Api_BackupServer) error

Backup creates a database snapshot and streams it to the client in chunks.

func (*Srv) Del

func (s *Srv) Del(ctx context.Context, in *pb.DelParams) (*pb.DelResponse, error)

Del implements the gRPC API service Del method, deleting the specified key and its corresponding value from the database and returning the deleted key(s). When the regex option is enabled, Del treats the "key" as a regex, deleting all matching keys.

func (*Srv) Get

func (s *Srv) Get(ctx context.Context, in *pb.GetParams) (*pb.GetResponse, error)

Get implements the gRPC API service Get method, retrieving keys. By default, it returns the value for "key". When the regex option is enabled, Get treats the "key" as a regex. When the keysOnly option is enabled, Get only returns the key(s) without the value(s).

func (*Srv) Put

func (s *Srv) Put(ctx context.Context, in *pb.PutParams) (*pb.PutResponse, error)

Put implements the gRPC API service Put method, adding a key-value pair to the database and returning the modified key(s). When the regex option is enabled, Put treats the "key" as a regex, updating all matching keys with the specified value.

func (*Srv) Run

func (s *Srv) Run() error

Run starts the database server. This is a blocking method and only returns if there is an error.

func (*Srv) Stats

func (s *Srv) Stats(ctx context.Context, in *pb.Delta) (*pb.Measures, error)

Stats implements the gRPC API service Stat method. It returns statistics over the given delta time range.

func (*Srv) Watch

func (s *Srv) Watch(in *pb.WatchParams, stream pb.Api_WatchServer) error

Watch implements the gRPC API service Watch method, enabling clients to watch over keys in the database. Operations on watched keys trigger events to the client. When the regex option is enabled, Watch treats "key" as a regex.

Note: Watch throws an error if the regex doesn't match any existing key in the database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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