func processGetChildrenReq(opReq OpReq, client kv.Client) *OpRep { xid := opReq.Hdr.Xid req := opReq.Req.(*GetChildrenReq) if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil { return err } children, err := client.GetChildren(req.Path.Value) if err != nil { return newBackendErrorRep(xid, 0, err) } return newRep( xid, 0, errOk, &GetChildrenRep{Children: children}, ) }
func processSetDataReq(opReq OpReq, client kv.Client) *OpRep { xid := opReq.Hdr.Xid req := opReq.Req.(*SetDataReq) if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil { return err } err := client.SetData(req.Path.Value, string(req.Data), req.Version) if err != nil { return newBackendErrorRep(xid, 0, err) } return newRep( xid, 0, errOk, &SetDataRep{Stat: newStat(0, 0, 0)}, ) }
func processExistsReq(opReq OpReq, client kv.Client) *OpRep { xid := opReq.Hdr.Xid req := opReq.Req.(*ExistsReq) if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil { return err } err := client.Exists(req.Path.Value) if err != nil { return newBackendErrorRep(xid, 0, err) } return newRep( xid, 0, errOk, &ExistsRep{Stat: newStat(0, 0, 0)}, ) }
func processDeleteReq(opReq OpReq, client kv.Client) *OpRep { xid := opReq.Hdr.Xid req := opReq.Req.(*DeleteReq) if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil { return err } err := client.Delete(req.Path.Value, req.Version) if err != nil { return newBackendErrorRep(xid, 0, err) } return newRep( xid, 0, errOk, &DeleteRep{}, ) }
func processCreateReq(opReq OpReq, client kv.Client) *OpRep { xid := opReq.Hdr.Xid req := opReq.Req.(*CreateReq) if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil { return err } err := client.Create(req.Path.Value, string(req.Data)) if err != nil { return newBackendErrorRep(xid, 0, err) } return newRep( xid, 0, errOk, &CreateRep{Path: req.Path.Value}, ) }
func processGetDataReq(opReq OpReq, client kv.Client) *OpRep { xid := opReq.Hdr.Xid req := opReq.Req.(*GetDataReq) if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil { return err } node, err := client.GetData(req.Path.Value) if err != nil { return newBackendErrorRep(xid, 0, err) } return newRep( xid, 0, errOk, &GetDataRep{ Data: []byte(node.Value), Stat: newStat(node.CreatedIndex, node.ModifiedIndex, len(node.Value)), }, ) }
func processCheckVersionReq(opReq OpReq, client kv.Client) *OpRep { xid := opReq.Hdr.Xid req := opReq.Req.(*CheckVersionReq) if err := newErrorRepIfInvalidPath(xid, 0, req.Path); err != nil { return err } node, err := client.GetData(req.Path.Value) if err != nil { return newBackendErrorRep(xid, 0, err) } if req.Version != int32(node.ModifiedIndex) { return newErrorRep(xid, 0, errBadVersion) } return newRep( xid, 0, errOk, &PingRep{}, ) }