[#323] client: Replace writeToMetaHeader method with function

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-08-23 20:55:00 +03:00 committed by fyrchik
parent 8c5333ea55
commit a926e5a1de
6 changed files with 8 additions and 21 deletions

View file

@ -52,19 +52,6 @@ func (x *prmCommonMeta) WithXHeaders(hs ...string) {
x.xHeaders = hs 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) { func writeXHeadersToMeta(xHeaders []string, h *v2session.RequestMetaHeader) {
if len(xHeaders) == 0 { if len(xHeaders) == 0 {
return return
@ -166,7 +153,7 @@ func (x contextCall) prepareRequest() {
meta.SetNetworkMagic(x.netMagic) meta.SetNetworkMagic(x.netMagic)
x.meta.writeToMetaHeader(meta) writeXHeadersToMeta(x.meta.xHeaders, meta)
} }
func (c *Client) prepareRequest(req request, meta *v2session.RequestMetaHeader) { func (c *Client) prepareRequest(req request, meta *v2session.RequestMetaHeader) {

View file

@ -114,7 +114,7 @@ func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResCon
// form meta header // form meta header
var meta v2session.RequestMetaHeader var meta v2session.RequestMetaHeader
prm.prmCommonMeta.writeToMetaHeader(&meta) writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
if prm.sessionSet { if prm.sessionSet {
var tokv2 v2session.Token var tokv2 v2session.Token
@ -456,7 +456,7 @@ func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (*
// form meta header // form meta header
var meta v2session.RequestMetaHeader var meta v2session.RequestMetaHeader
prm.prmCommonMeta.writeToMetaHeader(&meta) writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
if prm.tokSet { if prm.tokSet {
var tokv2 v2session.Token var tokv2 v2session.Token
@ -677,7 +677,7 @@ func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL)
// form meta header // form meta header
var meta v2session.RequestMetaHeader var meta v2session.RequestMetaHeader
prm.prmCommonMeta.writeToMetaHeader(&meta) writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
if prm.sessionSet { if prm.sessionSet {
var tokv2 v2session.Token var tokv2 v2session.Token

View file

@ -86,7 +86,7 @@ func (x *PrmObjectDelete) WithXHeaders(hs ...string) {
panic("slice of X-Headers with odd length") 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. // ResObjectDelete groups resulting values of ObjectDelete operation.

View file

@ -60,7 +60,7 @@ func (x prmObjectRead) writeToMetaHeader(h *v2session.RequestMetaHeader) {
h.SetSessionToken(&tokv2) h.SetSessionToken(&tokv2)
} }
x.prmCommonMeta.writeToMetaHeader(h) writeXHeadersToMeta(x.prmCommonMeta.xHeaders, h)
} }
// MarkRaw marks an intent to read physically stored object. // MarkRaw marks an intent to read physically stored object.

View file

@ -97,7 +97,7 @@ func (x *ObjectWriter) WithXHeaders(hs ...string) {
panic("slice of X-Headers with odd length") 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. // WriteHeader writes header of the object. Result means success.

View file

@ -275,7 +275,7 @@ func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*Ob
meta.SetSessionToken(&tokv2) meta.SetSessionToken(&tokv2)
} }
prm.prmCommonMeta.writeToMetaHeader(&meta) writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
// form request // form request
var req v2object.SearchRequest var req v2object.SearchRequest