func (r *clientRPC) AtomicDelete(conn io.Writer, req *clientRequest) { var res api.Response ok, err := r.s.AtomicDelete(req.Key, kvToLibKV(req.Previous)) if err != nil { setError(&res, err) } res.Completed = ok api.NewEncoder(conn).Encode(&res) }
func (r *clientRPC) Exists(conn io.Writer, req *clientRequest) { var res api.Response exists, err := r.s.Exists(req.Key) if err != nil { setError(&res, err) } res.Exists = exists api.NewEncoder(conn).Encode(&res) }
func (r *clientRPC) Get(conn io.Writer, req *clientRequest) { var res api.Response kv, err := r.s.Get(req.Key) if err != nil { setError(&res, err) api.Encode(&res, conn) return } res.KV = libkvToKV(kv) api.Encode(&res, conn) }
func (r *clientRPC) AtomicPut(conn io.Writer, req *clientRequest) { var res api.Response ok, kv, err := r.s.AtomicPut(req.Key, req.Value, kvToLibKV(req.Previous), &libkvstore.WriteOptions{TTL: req.TTL}) if err != nil { setError(&res, err) } else { res.Completed = ok res.KV = libkvToKV(kv) } api.NewEncoder(conn).Encode(&res) }
func (r *clientRPC) List(conn io.Writer, req *clientRequest) { var res api.Response ls, err := r.s.List(req.Key) if err != nil { setError(&res, err) } var apiLs []*api.KVPair for _, kv := range ls { apiLs = append(apiLs, libkvToKV(kv)) } res.List = apiLs api.NewEncoder(conn).Encode(&res) }
func setError(res *api.Response, err error) { if err == nil { return } switch err { case ErrKeyNotFound: e := errors.StoreKeyNotFound.WithMessage(err.Error()) res.Err = &e case ErrKeyModified: e := errors.StoreKeyModified.WithMessage(err.Error()) res.Err = &e case ErrCallNotSupported: e := errcode.ErrorCodeUnsupported.WithMessage(err.Error()) res.Err = &e default: e := errcode.ErrorCodeUnknown.WithMessage(err.Error()) res.Err = &e } }