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.
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package starmap
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
func (kv *RemoteKv) GetMap(key string) (StarMap, error) {
|
|
kv.kvmu.Lock()
|
|
defer kv.kvmu.Unlock()
|
|
defer kv.keepalive()
|
|
recv, err := kv.client.SendValueWait("GetMap", key, kv.TimeOut)
|
|
if err != nil {
|
|
return StarMapSample{}, err
|
|
}
|
|
if recv.Key == "error" {
|
|
return StarMapSample{}, errors.New(recv.Value)
|
|
}
|
|
value, err := decodeMap([]byte(recv.Value))
|
|
if err != nil {
|
|
return StarMapSample{}, err
|
|
}
|
|
return value, nil
|
|
}
|
|
|
|
func (kv *RemoteKv) StoreMap(value StarMap) error {
|
|
kv.kvmu.Lock()
|
|
defer kv.kvmu.Unlock()
|
|
defer kv.keepalive()
|
|
encodeData, err := encodeMap(value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
recv, err := kv.client.SendValueWait("StoreMap", string(encodeData), kv.TimeOut)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if recv.Key == "error" {
|
|
return errors.New(recv.Value)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (kv *RemoteKv) DeleteMap(value StarMap) error {
|
|
kv.kvmu.Lock()
|
|
defer kv.kvmu.Unlock()
|
|
defer kv.keepalive()
|
|
recv, err := kv.client.SendValueWait("DeleteMap", value.GetName(), kv.TimeOut)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if recv.Key == "error" {
|
|
return errors.New(recv.Value)
|
|
}
|
|
return nil
|
|
}
|