This commit is contained in:
cdle
2021-09-20 18:20:35 +08:00
parent 9823fc3bd5
commit b33c7b1096
7 changed files with 137 additions and 19 deletions
+1
View File
@@ -99,6 +99,7 @@ func handleMessage(sender Sender) {
rt := function.Handle(sender)
if rt != nil {
sender.Reply(rt)
sender.Finish()
}
return
}
+5
View File
@@ -24,6 +24,7 @@ type Sender interface {
Reply(...interface{}) (int, error)
Delete() error
Disappear(lifetime ...time.Duration)
Finish()
}
type Edit int
@@ -111,3 +112,7 @@ func (sender *Faker) Delete() error {
func (sender *Faker) Disappear(lifetime ...time.Duration) {
}
func (sender *Faker) Finish() {
}
+7 -7
View File
@@ -28,24 +28,24 @@ func initStore() {
}
}
func (bucket Bucket) Set(key string, value interface{}) {
func (bucket Bucket) Set(key interface{}, value interface{}) {
db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(bucket))
if b == nil {
b, _ = tx.CreateBucket([]byte(bucket))
}
b.Put([]byte(key), []byte(fmt.Sprint(value)))
b.Put([]byte(fmt.Sprint(key)), []byte(fmt.Sprint(value)))
return nil
})
}
func (bucket Bucket) Get(kv ...string) string {
func (bucket Bucket) Get(kv ...interface{}) string {
var key, value string
for i := range kv {
if i == 0 {
key = kv[0]
key = fmt.Sprint(kv[0])
} else {
value = kv[1]
value = fmt.Sprint(kv[1])
}
}
db.View(func(tx *bolt.Tx) error {
@@ -61,7 +61,7 @@ func (bucket Bucket) Get(kv ...string) string {
return value
}
func (bucket Bucket) GetInt(key string, vs ...int) int {
func (bucket Bucket) GetInt(key interface{}, vs ...int) int {
var value int
if len(vs) != 0 {
value = vs[0]
@@ -71,7 +71,7 @@ func (bucket Bucket) GetInt(key string, vs ...int) int {
if b == nil {
return nil
}
v := Int(string(b.Get([]byte(key))))
v := Int(string(b.Get([]byte(fmt.Sprint(key)))))
if v != 0 {
value = v
}