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.
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
4 years ago
|
package starmap
|
||
|
|
||
|
import "b612.me/notify"
|
||
|
|
||
|
type basicReply struct {
|
||
|
Key string
|
||
|
Value []byte
|
||
|
}
|
||
|
|
||
|
func (kv *RemoteKv) get(data notify.SMsg) string {
|
||
|
key := data.Value
|
||
|
value, err := Get(key)
|
||
|
if err != nil {
|
||
|
sendData, err := encode(basicReply{"error", []byte("key not exists")})
|
||
|
if err != nil {
|
||
|
kv.ErrMsg += err.Error()
|
||
|
return ""
|
||
|
}
|
||
|
data.Reply(string(sendData))
|
||
|
} else {
|
||
|
prepareData, err := encode(value)
|
||
|
if err != nil {
|
||
|
kv.ErrMsg += err.Error()
|
||
|
sendData, _ := encode(basicReply{"error", []byte(err.Error())})
|
||
|
data.Reply(string(sendData))
|
||
|
return ""
|
||
|
}
|
||
|
sendData, err := encode(basicReply{"ok", prepareData})
|
||
|
if err != nil {
|
||
|
kv.ErrMsg += err.Error()
|
||
|
sendData, _ := encode(basicReply{"error", []byte(err.Error())})
|
||
|
data.Reply(string(sendData))
|
||
|
return ""
|
||
|
}
|
||
|
data.Reply(string(sendData))
|
||
|
}
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
func (kv *RemoteKv) store(data notify.SMsg) string {
|
||
|
decodeData, err := decode([]byte(data.Value))
|
||
|
if err != nil {
|
||
|
return err.Error()
|
||
|
}
|
||
|
inf := decodeData.(*basicReply)
|
||
|
customStruct, err := decode(inf.Value)
|
||
|
if err != nil {
|
||
|
return err.Error()
|
||
|
}
|
||
|
err = Store(inf.Key, customStruct)
|
||
|
if err != nil {
|
||
|
return err.Error()
|
||
|
}
|
||
|
return "ok"
|
||
|
}
|
||
|
|
||
|
func (kv *RemoteKv) delete(data notify.SMsg) string {
|
||
|
err := Delete(data.Value)
|
||
|
if err != nil {
|
||
|
return err.Error()
|
||
|
}
|
||
|
return "ok"
|
||
|
}
|