From a926e5a1dec0c2fd4126fa78a0388784206f8d90 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 23 Aug 2022 20:55:00 +0300 Subject: [PATCH] [#323] client: Replace `writeToMetaHeader` method with function Signed-off-by: Evgenii Stratonikov --- client/common.go | 15 +-------------- client/container.go | 6 +++--- client/object_delete.go | 2 +- client/object_get.go | 2 +- client/object_put.go | 2 +- client/object_search.go | 2 +- 6 files changed, 8 insertions(+), 21 deletions(-) diff --git a/client/common.go b/client/common.go index da93cc1e..8ce2f727 100644 --- a/client/common.go +++ b/client/common.go @@ -52,19 +52,6 @@ func (x *prmCommonMeta) WithXHeaders(hs ...string) { x.xHeaders = hs } -func (x prmCommonMeta) writeToMetaHeader(h *v2session.RequestMetaHeader) { - if len(x.xHeaders) > 0 { - hs := make([]v2session.XHeader, len(x.xHeaders)/2) - - for i := 0; i < len(x.xHeaders); i += 2 { - hs[i].SetKey(x.xHeaders[i]) - hs[i].SetValue(x.xHeaders[i+1]) - } - - h.SetXHeaders(hs) - } -} - func writeXHeadersToMeta(xHeaders []string, h *v2session.RequestMetaHeader) { if len(xHeaders) == 0 { return @@ -166,7 +153,7 @@ func (x contextCall) prepareRequest() { meta.SetNetworkMagic(x.netMagic) - x.meta.writeToMetaHeader(meta) + writeXHeadersToMeta(x.meta.xHeaders, meta) } func (c *Client) prepareRequest(req request, meta *v2session.RequestMetaHeader) { diff --git a/client/container.go b/client/container.go index f1e21c21..60676bd2 100644 --- a/client/container.go +++ b/client/container.go @@ -114,7 +114,7 @@ func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResCon // form meta header var meta v2session.RequestMetaHeader - prm.prmCommonMeta.writeToMetaHeader(&meta) + writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta) if prm.sessionSet { var tokv2 v2session.Token @@ -456,7 +456,7 @@ func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (* // form meta header var meta v2session.RequestMetaHeader - prm.prmCommonMeta.writeToMetaHeader(&meta) + writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta) if prm.tokSet { var tokv2 v2session.Token @@ -677,7 +677,7 @@ func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL) // form meta header var meta v2session.RequestMetaHeader - prm.prmCommonMeta.writeToMetaHeader(&meta) + writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta) if prm.sessionSet { var tokv2 v2session.Token diff --git a/client/object_delete.go b/client/object_delete.go index eb7bb512..abd9a1f9 100644 --- a/client/object_delete.go +++ b/client/object_delete.go @@ -86,7 +86,7 @@ func (x *PrmObjectDelete) WithXHeaders(hs ...string) { panic("slice of X-Headers with odd length") } - prmCommonMeta{xHeaders: hs}.writeToMetaHeader(&x.meta) + writeXHeadersToMeta(hs, &x.meta) } // ResObjectDelete groups resulting values of ObjectDelete operation. diff --git a/client/object_get.go b/client/object_get.go index ab97d74d..7f4b3b25 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -60,7 +60,7 @@ func (x prmObjectRead) writeToMetaHeader(h *v2session.RequestMetaHeader) { h.SetSessionToken(&tokv2) } - x.prmCommonMeta.writeToMetaHeader(h) + writeXHeadersToMeta(x.prmCommonMeta.xHeaders, h) } // MarkRaw marks an intent to read physically stored object. diff --git a/client/object_put.go b/client/object_put.go index c5badc41..c6554ad9 100644 --- a/client/object_put.go +++ b/client/object_put.go @@ -97,7 +97,7 @@ func (x *ObjectWriter) WithXHeaders(hs ...string) { panic("slice of X-Headers with odd length") } - prmCommonMeta{xHeaders: hs}.writeToMetaHeader(&x.metaHdr) + writeXHeadersToMeta(hs, &x.metaHdr) } // WriteHeader writes header of the object. Result means success. diff --git a/client/object_search.go b/client/object_search.go index 17bdaac5..59314338 100644 --- a/client/object_search.go +++ b/client/object_search.go @@ -275,7 +275,7 @@ func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*Ob meta.SetSessionToken(&tokv2) } - prm.prmCommonMeta.writeToMetaHeader(&meta) + writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta) // form request var req v2object.SearchRequest