Documentation ¶
Index ¶
- Constants
- type BaseWatcher
- type Cacher
- func (c *Cacher) Count() int
- func (c *Cacher) Delete(key string, recursive bool) []string
- func (c *Cacher) Get(key string) map[string]interface{}
- func (c *Cacher) GetAll() map[string]interface{}
- func (c *Cacher) GetAllKeys() []string
- func (c *Cacher) Put(key string, value interface{})
- func (c *Cacher) Reset(data map[string]interface{})
- type ConvertFunc
- type Event
- type Receiver
- type Sender
- type Status
- type Watcher
Constants ¶
const ( // NIL represents a nil watcher, which will watch nothing NIL = "nil" // CONFIG represents a config watcher, watch /lain/config CONFIG = "config" // PODGROUP represents a podgroup watcher, watch /lain/deployd/pod_groups PODGROUP = "podgroup" // DEPENDS represents a depends watcher, watch /lain/deployd/depends DEPENDS = "depends" // NODES represents a node watcher, it's based on podgroup watcher NODES = "nodes" // CONTAINER represents a container watcher, it's based on podgroup watcher CONTAINER = "container" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseWatcher ¶
type BaseWatcher struct { Store store.Store Ctx context.Context *Sender // contains filtered or unexported fields }
BaseWatcher having a sender, store, and convert function. It read and watch data from store, and use convert() to convert, then use sender to cache data and broadcast the event.
func New ¶
func New(s store.Store, ctx context.Context, key string, convert ConvertFunc, ckey2skey func(string) string) (*BaseWatcher, error)
New create a new watcher
func (*BaseWatcher) Get ¶
func (w *BaseWatcher) Get(prefix string) (map[string]interface{}, error)
Get function get the newest data for keys having `prefix` prefix. it returned error only when key is empty. it return all the data when prefix is '*'
type Cacher ¶
type Cacher struct {
// contains filtered or unexported fields
}
Cacher is a simple cache, used to cache converted data from store
func (*Cacher) Delete ¶
Delete delete the key in cache, if recursive is true, all the keys having `key` prefix will be deleted it returns the key list which is deleted
func (*Cacher) Get ¶
Get find the values in cache, if key was found, return the map with only one key; or it will return all the KV data which key has `key` prefix
func (*Cacher) GetAllKeys ¶
type ConvertFunc ¶
ConvertFunc convert the data from store into a general type
type Event ¶
type Event struct { // ID is a event id, it is cumulative when you get a new event ID uint64 // Action is the event type, init, update, delete or error Action store.Action // Data is event data, it always return the newest data, no matter what the action is Data map[string]interface{} }
Event represents a watcher event
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver represents a receiver of sender, which can receive data from sender
type Sender ¶
Sender having a cache, when the data in cache changed, call Broadcast() sending new data to receivers.