update
This commit is contained in:
+26
-3
@@ -6,26 +6,40 @@ import (
|
|||||||
"github.com/cdle/sillyGirl/im"
|
"github.com/cdle/sillyGirl/im"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Buckets []Bucket
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
AddCommand("", []Function{
|
AddCommand("", []Function{
|
||||||
{
|
{
|
||||||
Rules: []string{"set ? ? ?"},
|
Rules: []string{"set ? ? ?"},
|
||||||
Handle: func(s im.Sender) interface{} {
|
Handle: func(s im.Sender) interface{} {
|
||||||
Bucket(s.Get(0)).Set(s.Get(1), s.Get(2))
|
b := Bucket(s.Get(0))
|
||||||
|
if !IsBucket(b) {
|
||||||
|
return errors.New("不存在的存储桶")
|
||||||
|
}
|
||||||
|
b.Set(s.Get(1), s.Get(2))
|
||||||
return "设置成功"
|
return "设置成功"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Rules: []string{"delete ? ?"},
|
Rules: []string{"delete ? ?"},
|
||||||
Handle: func(s im.Sender) interface{} {
|
Handle: func(s im.Sender) interface{} {
|
||||||
Bucket(s.Get(0)).Set(s.Get(1), "")
|
b := Bucket(s.Get(0))
|
||||||
|
if !IsBucket(b) {
|
||||||
|
return errors.New("不存在的存储桶")
|
||||||
|
}
|
||||||
|
b.Set(s.Get(1), "")
|
||||||
return "删除成功"
|
return "删除成功"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Rules: []string{"get ? ? ?"},
|
Rules: []string{"get ? ? ?"},
|
||||||
Handle: func(s im.Sender) interface{} {
|
Handle: func(s im.Sender) interface{} {
|
||||||
v := Bucket(s.Get(0)).Get(s.Get(1))
|
b := Bucket(s.Get(0))
|
||||||
|
if !IsBucket(b) {
|
||||||
|
return errors.New("不存在的存储桶")
|
||||||
|
}
|
||||||
|
v := b.Get(s.Get(1))
|
||||||
if v == "" {
|
if v == "" {
|
||||||
return errors.New("空值")
|
return errors.New("空值")
|
||||||
}
|
}
|
||||||
@@ -34,3 +48,12 @@ func init() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsBucket(b Bucket) bool {
|
||||||
|
for i := range Buckets {
|
||||||
|
if Buckets[i] == b {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user