Documentation ¶
Overview ¶
This package 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) memoryFader.Open() defer memoryFader.Close() memoryFader.Store(item) memoryFader.Size() // => 1 time.Sleep(3*time.Second) memoryFader.Size() // => 0
The multicast fader can be used to distribute `Store` operations via a multicast group. Other instances that listen to the same group, will perform that operation on thier own, so that each instance end up with the same data.
multicastFaderOne := fader.NewMulticast(memoryFaderOne, "224.0.0.1:1888", fader.DefaultKey) multicastFaderOne.Open() defer multicastFaderOne.Close() multicastFaderTwo := fader.NewMulticast(memoryFaderTwo, "224.0.0.1:1888", fader.DefaultKey) multicastFaderTwo.Open() defer multicastFaderTwo.Close() multicastFaderOne.Store(item) multicastFaderOne.Size() // => 1 time.Sleep(10*time.Millisecond) multicastFaderTwo.Size() // => 1
Index ¶
Constants ¶
const (
IDSize = 10
)
Variables ¶
var (
DefaultKey = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
)
Functions ¶
This section is empty.
Types ¶
type Fader ¶
type Fader interface { Open() error Close() error Store(Item) error Earliest() Item Select(string) []Item Detect(string) Item Size() int }
func 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 NewMulticast ¶
func NewMulticast( parent Fader, address string, key []byte, id []byte, itemReceivedHandler func(Item) bool, ) Fader
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. For testing purposes, a 10-byte long id can be set. 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.