Documentation ¶
Index ¶
- Constants
- func FileMd5(filepath string) (string, error)
- func ReadFile(filepath string) ([]byte, error)
- type AtomicBool
- type Cache
- func (c *Cache) Add(obj interface{}) error
- func (c *Cache) Clear()
- func (c *Cache) Delete(obj interface{}) error
- func (c *Cache) Get(obj interface{}) (item interface{}, exists bool, err error)
- func (c *Cache) GetByKey(key string) (item interface{}, exists bool, err error)
- func (c *Cache) List() []interface{}
- func (c *Cache) ListKeys() []string
- func (c *Cache) Num() int
- func (c *Cache) Replace(list []interface{}) error
- func (c *Cache) Update(obj interface{}) error
- type DataNoExist
- type EventHandler
- type FileEvent
- type FileEventType
- type FileWatcher
- type KeyError
- type ObjectKeyFunc
- type Store
Constants ¶
const ( // FileEventCreate file created FileEventCreate = iota // FileEventUpdate file updated FileEventUpdate // FileEventDelete file deleted FileEventDelete )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
AtomicBool thread safe bool type
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements Store interface with a safe map
func (*Cache) Get ¶
Get returns the requested item, or sets exists=false. Get is completely threadsafe as long as you treat all items as immutable.
func (*Cache) GetByKey ¶
GetByKey returns the request item, or exists=false. GetByKey is completely threadsafe as long as you treat all items as immutable.
func (*Cache) List ¶
func (c *Cache) List() []interface{}
List returns a list of all the items. List is completely threadsafe as long as you treat all items as immutable.
func (*Cache) ListKeys ¶
ListKeys returns a list of all the keys of the objects currently in the cache.
type DataNoExist ¶
type DataNoExist struct {
Obj interface{}
}
DataNoExist return when No data in Store
type EventHandler ¶
type EventHandler interface { OnAdd(obj interface{}) OnUpdate(oldObj interface{}, newObj interface{}) OnDelete(obj interface{}) }
EventHandler Handler interface for object changes
type FileEvent ¶
type FileEvent struct { Filename string Type FileEventType }
FileEvent event returned by file watcher
func NewFileEvent ¶
func NewFileEvent(filename string, t FileEventType) FileEvent
NewFileEvent new a file event
type FileWatcher ¶
FileWatcher watcher for a dir or a file
func NewFileWatcher ¶
func NewFileWatcher(period time.Duration) *FileWatcher
NewFileWatcher create filewatcher
func (*FileWatcher) WatchDir ¶
func (fw *FileWatcher) WatchDir(path string) (chan FileEvent, error)
WatchDir watch dir change when fsnotify.Write event is received, we check the file md5sum to see if there is a file content update because on different OS, there may be 1 to 2 fsnotify.Write events for a single file write operation
type KeyError ¶
type KeyError struct { Obj interface{} Err error }
KeyError wrapper error return from ObjectKeyFunc
type ObjectKeyFunc ¶
ObjectKeyFunc define make object to a uniq key
type Store ¶
type Store interface { Add(obj interface{}) error Update(obj interface{}) error Delete(obj interface{}) error List() []interface{} ListKeys() []string Get(obj interface{}) (item interface{}, exists bool, err error) GetByKey(key string) (item interface{}, exists bool, err error) //Num will return data counts in Store Num() int //Clear will drop all data in Store Clear() // Replace will delete the contents of the store, using instead the // given list. Store takes ownership of the list, you should not reference // it after calling this function. Replace([]interface{}) error }
Store is storage interface
func NewCache ¶
func NewCache(kfunc ObjectKeyFunc) Store
NewCache create cache with designated ObjectKeyFunc