You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
908 B
Go
49 lines
908 B
Go
package starmap
|
|
|
|
import (
|
|
"b612.me/notify"
|
|
)
|
|
|
|
func (kv *RemoteKv) getMap(data notify.SMsg) string {
|
|
kv.kvmu.Lock()
|
|
defer kv.kvmu.Unlock()
|
|
val, ok := kv.kvmap.kvMapPro[data.Value]
|
|
if !ok {
|
|
data.Key = "error"
|
|
data.Reply("key not exists")
|
|
return ""
|
|
}
|
|
encodeData, err := encodeMap(val)
|
|
if err != nil {
|
|
data.Key = "error"
|
|
data.Reply(err.Error())
|
|
return ""
|
|
}
|
|
return string(encodeData)
|
|
}
|
|
|
|
func (kv *RemoteKv) storeMap(data notify.SMsg) string {
|
|
kv.kvmu.Lock()
|
|
defer kv.kvmu.Unlock()
|
|
recvData, err := decodeMap([]byte(data.Value))
|
|
if err != nil {
|
|
data.Key = "error"
|
|
data.Reply(err.Error())
|
|
return ""
|
|
}
|
|
err = kv.kvmap.StoreMap(recvData)
|
|
if err != nil {
|
|
data.Key = "error"
|
|
data.Reply(err.Error())
|
|
return ""
|
|
}
|
|
return "ok"
|
|
}
|
|
|
|
func (kv *RemoteKv) deleteMap(data notify.SMsg) string {
|
|
kv.kvmu.Lock()
|
|
defer kv.kvmu.Unlock()
|
|
delete(kv.kvmap.kvMapPro, data.Value)
|
|
return "ok"
|
|
}
|