model

package
v1.20.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileEventCreate file created
	FileEventCreate = iota
	// FileEventUpdate file updated
	FileEventUpdate
	// FileEventDelete file deleted
	FileEventDelete
)

Variables

This section is empty.

Functions

func FileMd5

func FileMd5(filepath string) (string, error)

func ReadFile

func ReadFile(filepath string) ([]byte, error)

Types

type AtomicBool

type AtomicBool struct {
	// contains filtered or unexported fields
}

AtomicBool thread safe bool type

func NewAtomicBool

func NewAtomicBool() *AtomicBool

NewAtomicBool return AtomicBool obj

func (*AtomicBool) Set

func (ab *AtomicBool) Set(value bool)

Set set AtomicBool value

func (*AtomicBool) Value

func (ab *AtomicBool) Value() bool

Value get AtomicBool value

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache implements Store interface with a safe map

func (*Cache) Add

func (c *Cache) Add(obj interface{}) error

Add inserts an item into the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear will drop all data in Store

func (*Cache) Delete

func (c *Cache) Delete(obj interface{}) error

Delete removes an item from the cache.

func (*Cache) Get

func (c *Cache) Get(obj interface{}) (item interface{}, exists bool, err error)

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

func (c *Cache) GetByKey(key string) (item interface{}, exists bool, err error)

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

func (c *Cache) ListKeys() []string

ListKeys returns a list of all the keys of the objects currently in the cache.

func (*Cache) Num

func (c *Cache) Num() int

Num will return data counts in Store

func (*Cache) Replace

func (c *Cache) Replace(list []interface{}) error

Replace will delete the contents of 'c', using instead the given list. 'c' takes ownership of the list, you should not reference the list again after calling this function.

func (*Cache) Update

func (c *Cache) Update(obj interface{}) error

Update sets an item in the cache to its updated state.

type DataNoExist

type DataNoExist struct {
	Obj interface{}
}

DataNoExist return when No data in Store

func (DataNoExist) Error

func (k DataNoExist) Error() string

Error return string info

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 FileEventType

type FileEventType int

FileEventType event type for file watch

type FileWatcher

type FileWatcher struct {
	CurrentDir string
	Period     time.Duration
}

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

func (*FileWatcher) WatchFile

func (fw *FileWatcher) WatchFile(path string) (chan FileEvent, error)

WatchFile watch file change

type KeyError

type KeyError struct {
	Obj interface{}
	Err error
}

KeyError wrapper error return from ObjectKeyFunc

func (KeyError) Error

func (k KeyError) Error() string

Error return string info for KeyError

type ObjectKeyFunc

type ObjectKeyFunc func(obj interface{}) (string, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL