forked from TrueCloudLab/frostfs-api-go
[#225] pkg/client: Update object methods
- Support errors with SplitInfo in head and range methods. - Support raw flat in range method. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
ded06674ac
commit
139660c6ff
1 changed files with 39 additions and 7 deletions
|
@ -48,6 +48,8 @@ type ObjectHeaderParams struct {
|
||||||
type RangeDataParams struct {
|
type RangeDataParams struct {
|
||||||
addr *object.Address
|
addr *object.Address
|
||||||
|
|
||||||
|
raw bool
|
||||||
|
|
||||||
r *object.Range
|
r *object.Range
|
||||||
|
|
||||||
w io.Writer
|
w io.Writer
|
||||||
|
@ -690,6 +692,10 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, errors.Wrap(err, "incorrect object header signature")
|
return nil, errors.Wrap(err, "incorrect object header signature")
|
||||||
}
|
}
|
||||||
|
case *v2object.SplitInfo:
|
||||||
|
si := object.NewSplitInfoFromV2(v)
|
||||||
|
|
||||||
|
return nil, object.NewSplitInfoError(si)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unexpected Head object type %T", v))
|
panic(fmt.Sprintf("unexpected Head object type %T", v))
|
||||||
}
|
}
|
||||||
|
@ -721,6 +727,22 @@ func (p *RangeDataParams) Address() *object.Address {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *RangeDataParams) WithRaw(v bool) *RangeDataParams {
|
||||||
|
if p != nil {
|
||||||
|
p.raw = v
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *RangeDataParams) Raw() bool {
|
||||||
|
if p != nil {
|
||||||
|
return p.raw
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (p *RangeDataParams) WithRange(v *object.Range) *RangeDataParams {
|
func (p *RangeDataParams) WithRange(v *object.Range) *RangeDataParams {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.r = v
|
p.r = v
|
||||||
|
@ -799,6 +821,7 @@ func (c *Client) objectPayloadRangeV2(ctx context.Context, p *RangeDataParams, o
|
||||||
// fill body fields
|
// fill body fields
|
||||||
body.SetAddress(p.addr.ToV2())
|
body.SetAddress(p.addr.ToV2())
|
||||||
body.SetRange(p.r.ToV2())
|
body.SetRange(p.r.ToV2())
|
||||||
|
body.SetRaw(p.raw)
|
||||||
|
|
||||||
// sign the request
|
// sign the request
|
||||||
if err := signature.SignServiceMessage(c.key, req); err != nil {
|
if err := signature.SignServiceMessage(c.key, req); err != nil {
|
||||||
|
@ -832,14 +855,23 @@ func (c *Client) objectPayloadRangeV2(ctx context.Context, p *RangeDataParams, o
|
||||||
return nil, errors.Wrapf(err, "could not verify %T", resp)
|
return nil, errors.Wrapf(err, "could not verify %T", resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk := resp.GetBody().GetChunk()
|
switch v := resp.GetBody().GetRangePart().(type) {
|
||||||
|
case nil:
|
||||||
|
return nil, errNilObjectPart
|
||||||
|
case *v2object.GetRangePartChunk:
|
||||||
if p.w != nil {
|
if p.w != nil {
|
||||||
if _, err := p.w.Write(chunk); err != nil {
|
if _, err = p.w.Write(v.GetChunk()); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not write payload chunk")
|
return nil, errors.Wrap(err, "could not write payload chunk")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
payload = append(payload, chunk...)
|
payload = append(payload, v.GetChunk()...)
|
||||||
|
}
|
||||||
|
case *v2object.SplitInfo:
|
||||||
|
si := object.NewSplitInfoFromV2(v)
|
||||||
|
|
||||||
|
return nil, object.NewSplitInfoError(si)
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unexpected GetRange object type %T", v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue