Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyUpdate(obj any, upd any) (any, error)
- func ComputeDelta(old, now any) (any, error)
- func RegisterType(t *Type)
- type DB
- func (d *DB) Close() error
- func (d *DB) DebugDump(w io.Writer)
- func (d *DB) Delete(id []byte) error
- func (d *DB) Get(id []byte, target any) error
- func (d *DB) GetRaw(id []byte) (json.RawMessage, error)
- func (d *DB) GetStatus() Status
- func (d *DB) Has(id []byte) (bool, error)
- func (d *DB) SearchFirst(typ string, search map[string]any, target any) ([]byte, error)
- func (d *DB) SearchFirstRaw(typ string, search map[string]any) ([]byte, json.RawMessage, error)
- func (d *DB) Set(id []byte, val any) error
- func (d *DB) String() string
- func (d *DB) WaitReady()
- type RPC
- type Status
- type Type
- type TypeKey
Constants ¶
const ( RecordSet dblogType = iota // set the full value of a record RecordDelete // delete a record )
const ( PktGetInfo = 0x00 // GetInfo() PktGetLogIds = 0x01 // GetLogs(<peer>, <epoch>) PktFetchLog = 0x02 // FetchLog(<key>) uses no response packet id, response is always inline PktGetInfoResp = 0x80 // GetInfo()|Response PktLogPush = 0x40 // pushed log entry PktLogIdsPush = 0x41 // LogIdPush(<peer>, ...<logid>) ResponseFlag = 0x80 // response flag )
Variables ¶
var (
ErrKeyConflict = errors.New("record's key conflicts with an existing record")
)
Functions ¶
func ApplyUpdate ¶
ApplyUpdate will update the value of obj with upd, merging changes if both are objects. In most other cases upd will be returned as is. Both values should be of the same type, or nil.
func ComputeDelta ¶
ComputeDelta compares two objects (of type map[string]any) and returns an object that contains all the changes found in now while skipping any value that might be equal.
func RegisterType ¶
func RegisterType(t *Type)
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) GetRaw ¶
func (d *DB) GetRaw(id []byte) (json.RawMessage, error)
GetRaw returns the json value for a given id
func (*DB) SearchFirst ¶
SearchFirst will find the first record matching the search params and set target search must match an existing key in the provided type
func (*DB) SearchFirstRaw ¶
SearchFirstRaw will find the first record matching the search params and return its json value search must match an existing key in the provided type
type RPC ¶
type RPC interface { // All will send a given data object to all other RPC instances on the fleet // and will collect responses All(ctx context.Context, data []byte) ([]any, error) // Broadcast will do the same as All but will not wait for responses Broadcast(ctx context.Context, data []byte) error // Request will send a given object to a specific peer and return the response Request(ctx context.Context, id string, data []byte) ([]byte, error) // Send will send a given buffer to a specific peer and ignore the response Send(ctx context.Context, id string, data []byte) error // Self will return the id of the local peer, can be used for other instances // to contact here with Send(). Self() string // ListPeers returns a list of connected peers ListOnlinePeers() []string // CountAllPeers return the number of known connected or offline peers CountAllPeers() int // Connect connects this RPC instance incoming events to a given function // that will be called each time an event is received. Connect(cb func(context.Context, []byte) ([]byte, error)) }
RPC interface is standardized
type Type ¶
type Type struct { Name string `json:"name"` Keys []*TypeKey `json:"keys"` Version int `json:"version"` // version for the definition, can be set to zero }
Type is a registered index type used in records. A record of a given type will inherit the passed keys and be indexed based on it. Some keys will always exist, such as to ensure objects can be referenced at all times.
Types will be stored in the database to ensure records can be indexed properly on first try.