Documentation
¶
Index ¶
- type InMemStore
- func (p *InMemStore[K, T]) All() []T
- func (p *InMemStore[K, T]) Delete(key K)
- func (p *InMemStore[K, T]) Get(key K) (T, bool)
- func (p *InMemStore[K, T]) GetAndDelete(key K) (T, bool)
- func (p *InMemStore[K, T]) IsZero() bool
- func (p *InMemStore[K, T]) Len() int
- func (p *InMemStore[K, T]) Put(key K, data T)
- func (p *InMemStore[K, T]) Query(spec QueryFunc[K, T], limit int) []T
- func (p *InMemStore[K, T]) Update(key K, updates ...UpdateFunc[K, T])
- func (p *InMemStore[K, T]) Upsert(key K, init T, updates ...UpdateFunc[K, T])
- type QueryFunc
- type Store
- type UpdateFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InMemStore ¶
type InMemStore[K comparable, T any] struct { // contains filtered or unexported fields }
InMemStore in-memory peer store
func NewInMemStore ¶
func NewInMemStore[K comparable, V any]() *InMemStore[K, V]
NewInMemStore creates a new in-memory peer store
func (*InMemStore[K, T]) All ¶
func (p *InMemStore[K, T]) All() []T
All returns all stored values in the store
func (*InMemStore[K, T]) Delete ¶
func (p *InMemStore[K, T]) Delete(key K)
Delete removes the peer data from the store
func (*InMemStore[K, T]) Get ¶
func (p *InMemStore[K, T]) Get(key K) (T, bool)
Get returns peer's data and true if the peer is found otherwise empty structure and false
func (*InMemStore[K, T]) GetAndDelete ¶
func (p *InMemStore[K, T]) GetAndDelete(key K) (T, bool)
GetAndDelete combines Get operation and Delete in one call
func (*InMemStore[K, T]) IsZero ¶
func (p *InMemStore[K, T]) IsZero() bool
IsZero returns true if the store doesn't have a peer yet otherwise false
func (*InMemStore[K, T]) Len ¶
func (p *InMemStore[K, T]) Len() int
Len returns the count of all stored values
func (*InMemStore[K, T]) Put ¶
func (p *InMemStore[K, T]) Put(key K, data T)
Put adds the peer data to the store if the peer does not exist, otherwise update the current value
func (*InMemStore[K, T]) Query ¶
func (p *InMemStore[K, T]) Query(spec QueryFunc[K, T], limit int) []T
Query finds and returns the copy of values by specification conditions
func (*InMemStore[K, T]) Update ¶
func (p *InMemStore[K, T]) Update(key K, updates ...UpdateFunc[K, T])
Update applies update functions to the peer if it exists
func (*InMemStore[K, T]) Upsert ¶ added in v1.7.0
func (p *InMemStore[K, T]) Upsert(key K, init T, updates ...UpdateFunc[K, T])
Upsert applies the update functions to the value stored at key, inserting init first if the key is absent.
The lookup, the insert and the updates are one operation under one lock. A caller that composes the same thing out of Get, Put and Update instead has a window between them in which another goroutine can insert or modify the value, and the caller's own write then silently discards it.
type QueryFunc ¶
type QueryFunc[K comparable, V any] func(key K, data V) bool
QueryFunc is a function type for a specification function
func AndX ¶
func AndX[K comparable, V any](specs ...QueryFunc[K, V]) QueryFunc[K, V]
AndX combines multiple specification functions into one
type UpdateFunc ¶
type UpdateFunc[K comparable, V any] func(key K, item *V)
UpdateFunc is a function type for an item update functions