forked from TrueCloudLab/frostfs-sdk-go
[#168] client: Adopt replacement of pointer slices with struct slices
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
e89a0d88d2
commit
9c5d3d9dfa
7 changed files with 21 additions and 28 deletions
|
@ -71,14 +71,11 @@ func (x *prmCommonMeta) WithXHeaders(hs ...string) {
|
||||||
|
|
||||||
func (x prmCommonMeta) writeToMetaHeader(h *v2session.RequestMetaHeader) {
|
func (x prmCommonMeta) writeToMetaHeader(h *v2session.RequestMetaHeader) {
|
||||||
if len(x.xHeaders) > 0 {
|
if len(x.xHeaders) > 0 {
|
||||||
hs := make([]*v2session.XHeader, 0, len(x.xHeaders)/2)
|
hs := make([]v2session.XHeader, len(x.xHeaders)/2)
|
||||||
|
|
||||||
for i := 0; i < len(x.xHeaders); i += 2 {
|
for i := 0; i < len(x.xHeaders); i += 2 {
|
||||||
var h v2session.XHeader
|
hs[i].SetKey(x.xHeaders[i])
|
||||||
h.SetKey(x.xHeaders[i])
|
hs[i].SetValue(x.xHeaders[i+1])
|
||||||
h.SetValue(x.xHeaders[i+1])
|
|
||||||
|
|
||||||
hs = append(hs, &h)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h.SetXHeaders(hs)
|
h.SetXHeaders(hs)
|
||||||
|
|
|
@ -255,17 +255,17 @@ func (x *PrmContainerList) SetAccount(id owner.ID) {
|
||||||
type ResContainerList struct {
|
type ResContainerList struct {
|
||||||
statusRes
|
statusRes
|
||||||
|
|
||||||
ids []*cid.ID
|
ids []cid.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Containers returns list of identifiers of the account-owned containers.
|
// Containers returns list of identifiers of the account-owned containers.
|
||||||
//
|
//
|
||||||
// Client doesn't retain value so modification is safe.
|
// Client doesn't retain value so modification is safe.
|
||||||
func (x ResContainerList) Containers() []*cid.ID {
|
func (x ResContainerList) Containers() []cid.ID {
|
||||||
return x.ids
|
return x.ids
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ResContainerList) setContainers(ids []*cid.ID) {
|
func (x *ResContainerList) setContainers(ids []cid.ID) {
|
||||||
x.ids = ids
|
x.ids = ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,10 +319,10 @@ func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResC
|
||||||
cc.result = func(r responseV2) {
|
cc.result = func(r responseV2) {
|
||||||
resp := r.(*v2container.ListResponse)
|
resp := r.(*v2container.ListResponse)
|
||||||
|
|
||||||
ids := make([]*cid.ID, 0, len(resp.GetBody().GetContainerIDs()))
|
ids := make([]cid.ID, len(resp.GetBody().GetContainerIDs()))
|
||||||
|
|
||||||
for _, cidV2 := range resp.GetBody().GetContainerIDs() {
|
for i, cidV2 := range resp.GetBody().GetContainerIDs() {
|
||||||
ids = append(ids, cid.NewFromV2(cidV2))
|
ids[i] = *cid.NewFromV2(&cidV2)
|
||||||
}
|
}
|
||||||
|
|
||||||
res.setContainers(ids)
|
res.setContainers(ids)
|
||||||
|
@ -695,9 +695,9 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounce
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert list of SDK announcement structures into NeoFS-API v2 list
|
// convert list of SDK announcement structures into NeoFS-API v2 list
|
||||||
v2announce := make([]*v2container.UsedSpaceAnnouncement, 0, len(prm.announcements))
|
v2announce := make([]v2container.UsedSpaceAnnouncement, len(prm.announcements))
|
||||||
for i := range prm.announcements {
|
for i := range prm.announcements {
|
||||||
v2announce = append(v2announce, prm.announcements[i].ToV2())
|
v2announce[i] = *prm.announcements[i].ToV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare body of the NeoFS-API v2 request and request itself
|
// prepare body of the NeoFS-API v2 request and request itself
|
||||||
|
|
|
@ -71,10 +71,9 @@ func (x *PrmObjectHash) SetRangeList(r ...uint64) {
|
||||||
panic("odd number of range parameters")
|
panic("odd number of range parameters")
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := make([]*v2object.Range, ln/2)
|
rs := make([]v2object.Range, ln/2)
|
||||||
|
|
||||||
for i := 0; i < ln/2; i++ {
|
for i := 0; i < ln/2; i++ {
|
||||||
rs[i] = new(v2object.Range)
|
|
||||||
rs[i].SetOffset(r[2*i])
|
rs[i].SetOffset(r[2*i])
|
||||||
rs[i].SetLength(r[2*i+1])
|
rs[i].SetLength(r[2*i+1])
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ type ObjectListReader struct {
|
||||||
// initially bound to contextCall
|
// initially bound to contextCall
|
||||||
bodyResp v2object.SearchResponseBody
|
bodyResp v2object.SearchResponseBody
|
||||||
|
|
||||||
tail []*v2refs.ObjectID
|
tail []v2refs.ObjectID
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseKey specifies private key to sign the requests.
|
// UseKey specifies private key to sign the requests.
|
||||||
|
@ -130,7 +130,7 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < read; i++ {
|
for i := 0; i < read; i++ {
|
||||||
buf[i] = *oid.NewIDFromV2(x.tail[i]) // need smth better
|
buf[i] = *oid.NewIDFromV2(&x.tail[i]) // need smth better
|
||||||
}
|
}
|
||||||
|
|
||||||
x.tail = x.tail[read:]
|
x.tail = x.tail[read:]
|
||||||
|
@ -140,7 +140,7 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var ok bool
|
var ok bool
|
||||||
var ids []*v2refs.ObjectID
|
var ids []v2refs.ObjectID
|
||||||
var i, ln, rem int
|
var i, ln, rem int
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -164,7 +164,7 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 0; i < ln; i++ {
|
for i = 0; i < ln; i++ {
|
||||||
buf[read+i] = *oid.NewIDFromV2(ids[i]) // need smth better
|
buf[read+i] = *oid.NewIDFromV2(&ids[i]) // need smth better
|
||||||
}
|
}
|
||||||
|
|
||||||
read += ln
|
read += ln
|
||||||
|
|
|
@ -175,9 +175,9 @@ func testListReaderResponse(t *testing.T) (*ObjectListReader, func(id []oid.ID)
|
||||||
resp := new(object.SearchResponse)
|
resp := new(object.SearchResponse)
|
||||||
resp.SetBody(new(object.SearchResponseBody))
|
resp.SetBody(new(object.SearchResponseBody))
|
||||||
|
|
||||||
v2id := make([]*refs.ObjectID, len(id))
|
v2id := make([]refs.ObjectID, len(id))
|
||||||
for i := range id {
|
for i := range id {
|
||||||
v2id[i] = id[i].ToV2()
|
v2id[i] = *id[i].ToV2()
|
||||||
}
|
}
|
||||||
resp.GetBody().SetIDList(v2id)
|
resp.GetBody().SetIDList(v2id)
|
||||||
err := signatureV2.SignServiceMessage(&p.PrivateKey, resp)
|
err := signatureV2.SignServiceMessage(&p.PrivateKey, resp)
|
||||||
|
|
|
@ -65,11 +65,8 @@ func (c *Client) AnnounceLocalTrust(ctx context.Context, prm PrmAnnounceLocalTru
|
||||||
reqBody := new(v2reputation.AnnounceLocalTrustRequestBody)
|
reqBody := new(v2reputation.AnnounceLocalTrustRequestBody)
|
||||||
reqBody.SetEpoch(prm.epoch)
|
reqBody.SetEpoch(prm.epoch)
|
||||||
|
|
||||||
trusts := make([]*reputation.Trust, 0, len(prm.trusts))
|
trusts := make([]reputation.Trust, len(prm.trusts))
|
||||||
|
copy(trusts, prm.trusts)
|
||||||
for i := range prm.trusts {
|
|
||||||
trusts = append(trusts, &prm.trusts[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
reqBody.SetTrusts(reputation.TrustsToV2(trusts))
|
reqBody.SetTrusts(reputation.TrustsToV2(trusts))
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (x *WrongMagicNumber) WriteCorrectMagic(magic uint64) {
|
||||||
d.SetValue(buf)
|
d.SetValue(buf)
|
||||||
|
|
||||||
// attach the detail
|
// attach the detail
|
||||||
x.v2.AppendDetails(&d)
|
x.v2.AppendDetails(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CorrectMagic returns network magic returned by the server.
|
// CorrectMagic returns network magic returned by the server.
|
||||||
|
|
Loading…
Reference in a new issue