Documentation ¶
Overview ¶
Package fader provides an interface to store and fetch items. The implementation is responsible for the removal after a expiry period.
Example for a memory fader, that expires items after 2 seconds
memoryFader := fader.NewMemory(2*time.Second) defer memoryFader.Close() memoryFader.Put([]byte("key"), time.Now(), []byte("value")) memoryFader.Size() // => 1 time.Sleep(3*time.Second) memoryFader.Size() // => 0
The multicast fader can be used to distribute `Put` operations via a multicast group. Other instances that listen to the same group, will perform that operation on their own, so that each instance end up with the same data.
multicastFaderOne := fader.NewMulticast(memoryFaderOne, "224.0.0.1:1888", key) defer multicastFaderOne.Close() multicastFaderTwo := fader.NewMulticast(memoryFaderTwo, "224.0.0.1:1888", key) defer multicastFaderTwo.Close() multicastFaderOne.Put([]byte("key"), time.Now(), []byte("value")) multicastFaderOne.Size() // => 1 time.Sleep(10*time.Millisecond) multicastFaderTwo.Size() // => 1
Index ¶
- Variables
- type Fader
- type Memory
- func (m *Memory) Clear()
- func (m *Memory) Close() error
- func (m *Memory) Earliest() ([]byte, time.Time, []byte)
- func (m *Memory) Get(key []byte) (time.Time, []byte)
- func (m *Memory) Put(key []byte, t time.Time, value []byte) error
- func (m *Memory) Select(key []byte) ([]time.Time, [][]byte)
- func (m *Memory) Size() int
- type Multicast
- func (m *Multicast) Clear()
- func (m *Multicast) Close() error
- func (m *Multicast) Earliest() ([]byte, time.Time, []byte)
- func (m *Multicast) Get(key []byte) (time.Time, []byte)
- func (m *Multicast) Put(key []byte, time time.Time, value []byte) error
- func (m *Multicast) Select(key []byte) ([]time.Time, [][]byte)
- func (m *Multicast) Size() int
- type ReceivedHandler
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidKeyLength = errors.New("invalid key length")
ErrInvalidKeyLength is returns if a key with an invalid length is provided. Valid lengths are 16, 24 and 32.
Functions ¶
This section is empty.
Types ¶
type Fader ¶
type Fader interface { Put([]byte, time.Time, []byte) error Get([]byte) (time.Time, []byte) Earliest() ([]byte, time.Time, []byte) Select([]byte) ([]time.Time, [][]byte) Size() int Clear() Close() error }
Fader defines the fader interface.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory implements a memory fader.
func NewMemory ¶
NewMemory creates a Fader instance that stores all data in the Memory. The expiresIn parameter defines after which period a stored item will be removed.
func (*Memory) Clear ¶ added in v0.3.0
func (m *Memory) Clear()
Clear removes all items from the fader.
func (*Memory) Get ¶
Get returns time and value for the provided key. If no such key exists, a value of nil is returned.
type Multicast ¶
type Multicast struct {
// contains filtered or unexported fields
}
Multicast implements a multicast faader.
func NewMulticast ¶
func NewMulticast( parent Fader, address string, key []byte, id []byte, itemReceivedHandler ReceivedHandler, ) (*Multicast, error)
NewMulticast creates a Fader instance that delegates all calls to a parent Fader instance. Additional to that, all store-operations are published to a Multicast group which is specified by the given address. All packets will encrypted with AES-GCM using the given key. The length of the key's byte-slice, can be 16, 24 or 32 and will define if AES-128, AES-192 or AES-256 is used. A 10-byte long id can be set to avoid collisions. If no id is nil, a random id will be generated. The argument can take a function that is called every time an item is received. If the function is nil or returns true, the received item will be stored in the parent fader. Otherwise, the item will be dismissed.
func (*Multicast) Clear ¶ added in v0.3.0
func (m *Multicast) Clear()
Clear performs a clear on the parent fader.
func (*Multicast) Earliest ¶
Earliest returns key, time and value of the earliest item in the fader.
func (*Multicast) Get ¶
Get returns time and value for the provided key. If no such key exists, a value of nil is returned.