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 ¶
- Variables
- type OptFunc
- type Srv
- func (s *Srv) Backup(in *pb.ChunkSize, stream pb.Api_BackupServer) error
- func (s *Srv) Del(ctx context.Context, in *pb.DelParams) (*pb.DelResponse, error)
- func (s *Srv) Get(ctx context.Context, in *pb.GetParams) (*pb.GetResponse, error)
- func (s *Srv) Put(ctx context.Context, in *pb.PutParams) (*pb.PutResponse, error)
- func (s *Srv) Run() error
- func (s *Srv) Stats(ctx context.Context, in *pb.Delta) (*pb.Measures, error)
- func (s *Srv) Watch(in *pb.WatchParams, stream pb.Api_WatchServer) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 WithEventQueueSize ¶
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 ¶
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 ¶
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 (*Srv) Del ¶
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 ¶
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 ¶
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 ¶
Run starts the database server. This is a blocking method and only returns if there is an error.
func (*Srv) Stats ¶
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.