Files
Sillyv2/core/storage/main.go
T
2023-06-01 08:41:54 +08:00

63 lines
1.2 KiB
Go

package storage
type Listen struct {
UUID string
Name string
Key string
Handle func(old string, new string, key string) *Final
}
var Listens []Listen
var DisableHandle = func(uuid string) {
for i := range Listens {
if Listens[i].UUID == uuid {
Listens[i].Handle = func(old, new, key string) *Final {
return nil
}
}
}
}
type Bucket interface {
Set(interface{}, interface{}) (string, error)
Copy(string) Bucket
IsEmpty() (bool, error)
Size() (int64, error)
Delete() error
Type() string
Buckets() []string
GetString(...interface{}) string
GetBytes(string) []byte
GetInt(string, ...int) int
GetBool(string, ...bool) bool
Foreach(func([]byte, []byte) error)
Create(interface{}) error
First(interface{}) error
String() string
GetName() string
Keys() ([]string, error)
}
type Final struct {
Now string
Message string
Error error
}
func Watch(bucket Bucket, key interface{}, handle func(old string, new string, key string) *Final, uuid ...string) {
k := "*"
if key != nil {
k = key.(string)
}
listen := Listen{
Name: bucket.GetName(),
Key: k,
Handle: handle,
}
if len(uuid) != 0 {
listen.UUID = uuid[0]
}
Listens = append(Listens, listen)
}