forked from TrueCloudLab/frostfs-sdk-go
[#323] client: Unify parameter processing for Get* methods
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
992b26a3ff
commit
02bc2bc236
1 changed files with 23 additions and 66 deletions
|
@ -27,11 +27,7 @@ type prmObjectRead struct {
|
||||||
|
|
||||||
raw bool
|
raw bool
|
||||||
|
|
||||||
cnrSet bool
|
addr v2refs.Address
|
||||||
cnrID cid.ID
|
|
||||||
|
|
||||||
objSet bool
|
|
||||||
objID oid.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithXHeaders specifies list of extended headers (string key-value pairs)
|
// WithXHeaders specifies list of extended headers (string key-value pairs)
|
||||||
|
@ -82,15 +78,17 @@ func (x *prmObjectRead) WithBearerToken(t bearer.Token) {
|
||||||
// FromContainer specifies NeoFS container of the object.
|
// FromContainer specifies NeoFS container of the object.
|
||||||
// Required parameter.
|
// Required parameter.
|
||||||
func (x *prmObjectRead) FromContainer(id cid.ID) {
|
func (x *prmObjectRead) FromContainer(id cid.ID) {
|
||||||
x.cnrID = id
|
var cnrV2 v2refs.ContainerID
|
||||||
x.cnrSet = true
|
id.WriteToV2(&cnrV2)
|
||||||
|
x.addr.SetContainerID(&cnrV2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByID specifies identifier of the requested object.
|
// ByID specifies identifier of the requested object.
|
||||||
// Required parameter.
|
// Required parameter.
|
||||||
func (x *prmObjectRead) ByID(id oid.ID) {
|
func (x *prmObjectRead) ByID(id oid.ID) {
|
||||||
x.objID = id
|
var objV2 v2refs.ObjectID
|
||||||
x.objSet = true
|
id.WriteToV2(&objV2)
|
||||||
|
x.addr.SetObjectID(&objV2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrmObjectGet groups parameters of ObjectGetInit operation.
|
// PrmObjectGet groups parameters of ObjectGetInit operation.
|
||||||
|
@ -301,29 +299,17 @@ func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectRe
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
case ctx == nil:
|
||||||
panic(panicMsgMissingContext)
|
panic(panicMsgMissingContext)
|
||||||
case !prm.cnrSet:
|
case prm.addr.GetContainerID() == nil:
|
||||||
panic(panicMsgMissingContainer)
|
panic(panicMsgMissingContainer)
|
||||||
case !prm.objSet:
|
case prm.addr.GetObjectID() == nil:
|
||||||
panic(panicMsgMissingObject)
|
panic(panicMsgMissingObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
addr v2refs.Address
|
|
||||||
oidV2 v2refs.ObjectID
|
|
||||||
cidV2 v2refs.ContainerID
|
|
||||||
)
|
|
||||||
|
|
||||||
prm.objID.WriteToV2(&oidV2)
|
|
||||||
prm.cnrID.WriteToV2(&cidV2)
|
|
||||||
|
|
||||||
addr.SetContainerID(&cidV2)
|
|
||||||
addr.SetObjectID(&oidV2)
|
|
||||||
|
|
||||||
// form request body
|
// form request body
|
||||||
var body v2object.GetRequestBody
|
var body v2object.GetRequestBody
|
||||||
|
|
||||||
body.SetRaw(prm.raw)
|
body.SetRaw(prm.raw)
|
||||||
body.SetAddress(&addr)
|
body.SetAddress(&prm.addr)
|
||||||
|
|
||||||
// form request
|
// form request
|
||||||
var req v2object.GetRequest
|
var req v2object.GetRequest
|
||||||
|
@ -435,29 +421,17 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
case ctx == nil:
|
||||||
panic(panicMsgMissingContext)
|
panic(panicMsgMissingContext)
|
||||||
case !prm.cnrSet:
|
case prm.addr.GetContainerID() == nil:
|
||||||
panic(panicMsgMissingContainer)
|
panic(panicMsgMissingContainer)
|
||||||
case !prm.objSet:
|
case prm.addr.GetObjectID() == nil:
|
||||||
panic(panicMsgMissingObject)
|
panic(panicMsgMissingObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
addrV2 v2refs.Address
|
|
||||||
oidV2 v2refs.ObjectID
|
|
||||||
cidV2 v2refs.ContainerID
|
|
||||||
)
|
|
||||||
|
|
||||||
prm.objID.WriteToV2(&oidV2)
|
|
||||||
prm.cnrID.WriteToV2(&cidV2)
|
|
||||||
|
|
||||||
addrV2.SetContainerID(&cidV2)
|
|
||||||
addrV2.SetObjectID(&oidV2)
|
|
||||||
|
|
||||||
// form request body
|
// form request body
|
||||||
var body v2object.HeadRequestBody
|
var body v2object.HeadRequestBody
|
||||||
|
|
||||||
body.SetRaw(prm.raw)
|
body.SetRaw(prm.raw)
|
||||||
body.SetAddress(&addrV2)
|
body.SetAddress(&prm.addr)
|
||||||
|
|
||||||
// form request
|
// form request
|
||||||
var req v2object.HeadRequest
|
var req v2object.HeadRequest
|
||||||
|
@ -472,7 +446,7 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH
|
||||||
res ResObjectHead
|
res ResObjectHead
|
||||||
)
|
)
|
||||||
|
|
||||||
res.idObj = prm.objID
|
_ = res.idObj.ReadFromV2(*prm.addr.GetObjectID())
|
||||||
|
|
||||||
c.initCallContext(&cc)
|
c.initCallContext(&cc)
|
||||||
if prm.keySet {
|
if prm.keySet {
|
||||||
|
@ -507,19 +481,19 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH
|
||||||
type PrmObjectRange struct {
|
type PrmObjectRange struct {
|
||||||
prmObjectRead
|
prmObjectRead
|
||||||
|
|
||||||
off, ln uint64
|
rng v2object.Range
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOffset sets offset of the payload range to be read.
|
// SetOffset sets offset of the payload range to be read.
|
||||||
// Zero by default.
|
// Zero by default.
|
||||||
func (x *PrmObjectRange) SetOffset(off uint64) {
|
func (x *PrmObjectRange) SetOffset(off uint64) {
|
||||||
x.off = off
|
x.rng.SetOffset(off)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLength sets length of the payload range to be read.
|
// SetLength sets length of the payload range to be read.
|
||||||
// Must be positive.
|
// Must be positive.
|
||||||
func (x *PrmObjectRange) SetLength(ln uint64) {
|
func (x *PrmObjectRange) SetLength(ln uint64) {
|
||||||
x.ln = ln
|
x.rng.SetLength(ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResObjectRange groups the final result values of ObjectRange operation.
|
// ResObjectRange groups the final result values of ObjectRange operation.
|
||||||
|
@ -701,37 +675,20 @@ func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*Obje
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
case ctx == nil:
|
||||||
panic(panicMsgMissingContext)
|
panic(panicMsgMissingContext)
|
||||||
case !prm.cnrSet:
|
case prm.addr.GetContainerID() == nil:
|
||||||
panic(panicMsgMissingContainer)
|
panic(panicMsgMissingContainer)
|
||||||
case !prm.objSet:
|
case prm.addr.GetObjectID() == nil:
|
||||||
panic(panicMsgMissingObject)
|
panic(panicMsgMissingObject)
|
||||||
case prm.ln == 0:
|
case prm.rng.GetLength() == 0:
|
||||||
panic("zero range length")
|
panic("zero range length")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
addrV2 v2refs.Address
|
|
||||||
oidV2 v2refs.ObjectID
|
|
||||||
cidV2 v2refs.ContainerID
|
|
||||||
)
|
|
||||||
|
|
||||||
prm.objID.WriteToV2(&oidV2)
|
|
||||||
prm.cnrID.WriteToV2(&cidV2)
|
|
||||||
|
|
||||||
addrV2.SetContainerID(&cidV2)
|
|
||||||
addrV2.SetObjectID(&oidV2)
|
|
||||||
|
|
||||||
var rng v2object.Range
|
|
||||||
|
|
||||||
rng.SetOffset(prm.off)
|
|
||||||
rng.SetLength(prm.ln)
|
|
||||||
|
|
||||||
// form request body
|
// form request body
|
||||||
var body v2object.GetRangeRequestBody
|
var body v2object.GetRangeRequestBody
|
||||||
|
|
||||||
body.SetRaw(prm.raw)
|
body.SetRaw(prm.raw)
|
||||||
body.SetAddress(&addrV2)
|
body.SetAddress(&prm.addr)
|
||||||
body.SetRange(&rng)
|
body.SetRange(&prm.rng)
|
||||||
|
|
||||||
// form request
|
// form request
|
||||||
var req v2object.GetRangeRequest
|
var req v2object.GetRangeRequest
|
||||||
|
@ -746,7 +703,7 @@ func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*Obje
|
||||||
stream *rpcapi.ObjectRangeResponseReader
|
stream *rpcapi.ObjectRangeResponseReader
|
||||||
)
|
)
|
||||||
|
|
||||||
r.remainingPayloadLen = int(prm.ln)
|
r.remainingPayloadLen = int(prm.rng.GetLength())
|
||||||
|
|
||||||
ctx, r.cancelCtxStream = context.WithCancel(ctx)
|
ctx, r.cancelCtxStream = context.WithCancel(ctx)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue