From 1d5773b6ffa0e7e4a55f0fbd079ca36e059aa502 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 17 Aug 2020 13:11:44 +0300 Subject: [PATCH] v2/service: Replace request header converters Signed-off-by: Leonard Lyubich --- v2/accounting/convert.go | 43 ++-------------------------------------- v2/service/convert.go | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/v2/accounting/convert.go b/v2/accounting/convert.go index 9f049431..74d96c55 100644 --- a/v2/accounting/convert.go +++ b/v2/accounting/convert.go @@ -4,7 +4,6 @@ import ( accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc" "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/service" - grpcService "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" ) func BalanceRequestBodyToGRPCMessage(b *BalanceRequestBody) *accounting.BalanceRequest_Body { @@ -35,44 +34,6 @@ func BalanceRequestBodyFromGRPCMessage(m *accounting.BalanceRequest_Body) *Balan return b } -func headersToGRPC( - src interface { - GetRequestMetaHeader() *service.RequestMetaHeader - GetRequestVerificationHeader() *service.RequestVerificationHeader - }, - dst interface { - SetMetaHeader(*grpcService.RequestMetaHeader) - SetVerifyHeader(*grpcService.RequestVerificationHeader) - }, -) { - dst.SetMetaHeader( - service.RequestMetaHeaderToGRPCMessage(src.GetRequestMetaHeader()), - ) - - dst.SetVerifyHeader( - service.RequestVerificationHeaderToGRPCMessage(src.GetRequestVerificationHeader()), - ) -} - -func headersFromGRPC( - src interface { - GetMetaHeader() *grpcService.RequestMetaHeader - GetVerifyHeader() *grpcService.RequestVerificationHeader - }, - dst interface { - SetRequestMetaHeader(*service.RequestMetaHeader) - SetRequestVerificationHeader(*service.RequestVerificationHeader) - }, -) { - dst.SetRequestMetaHeader( - service.RequestMetaHeaderFromGRPCMessage(src.GetMetaHeader()), - ) - - dst.SetRequestVerificationHeader( - service.RequestVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), - ) -} - func BalanceRequestToGRPCMessage(b *BalanceRequest) *accounting.BalanceRequest { if b == nil { return nil @@ -84,7 +45,7 @@ func BalanceRequestToGRPCMessage(b *BalanceRequest) *accounting.BalanceRequest { BalanceRequestBodyToGRPCMessage(b.GetBody()), ) - headersToGRPC(b, m) + service.RequestHeadersToGRPC(b, m) return m } @@ -100,7 +61,7 @@ func BalanceRequestFromGRPCMessage(m *accounting.BalanceRequest) *BalanceRequest BalanceRequestBodyFromGRPCMessage(m.GetBody()), ) - headersFromGRPC(m, b) + service.RequestHeadersFromGRPC(m, b) return b } diff --git a/v2/service/convert.go b/v2/service/convert.go index eb8a10a8..c3306f36 100644 --- a/v2/service/convert.go +++ b/v2/service/convert.go @@ -325,3 +325,41 @@ func BearerTokenBodyFromGRPCMessage(m *service.BearerToken_Body) *BearerTokenBod return bt } + +func RequestHeadersToGRPC( + src interface { + GetRequestMetaHeader() *RequestMetaHeader + GetRequestVerificationHeader() *RequestVerificationHeader + }, + dst interface { + SetMetaHeader(*service.RequestMetaHeader) + SetVerifyHeader(*service.RequestVerificationHeader) + }, +) { + dst.SetMetaHeader( + RequestMetaHeaderToGRPCMessage(src.GetRequestMetaHeader()), + ) + + dst.SetVerifyHeader( + RequestVerificationHeaderToGRPCMessage(src.GetRequestVerificationHeader()), + ) +} + +func RequestHeadersFromGRPC( + src interface { + GetMetaHeader() *service.RequestMetaHeader + GetVerifyHeader() *service.RequestVerificationHeader + }, + dst interface { + SetRequestMetaHeader(*RequestMetaHeader) + SetRequestVerificationHeader(*RequestVerificationHeader) + }, +) { + dst.SetRequestMetaHeader( + RequestMetaHeaderFromGRPCMessage(src.GetMetaHeader()), + ) + + dst.SetRequestVerificationHeader( + RequestVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), + ) +}