v2/service: Replace request header converters

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-17 13:11:44 +03:00 committed by Stanislav Bogatyrev
parent 18737e128c
commit 1d5773b6ff
2 changed files with 40 additions and 41 deletions

View file

@ -4,7 +4,6 @@ import (
accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc" 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/refs"
"github.com/nspcc-dev/neofs-api-go/v2/service" "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 { func BalanceRequestBodyToGRPCMessage(b *BalanceRequestBody) *accounting.BalanceRequest_Body {
@ -35,44 +34,6 @@ func BalanceRequestBodyFromGRPCMessage(m *accounting.BalanceRequest_Body) *Balan
return b 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 { func BalanceRequestToGRPCMessage(b *BalanceRequest) *accounting.BalanceRequest {
if b == nil { if b == nil {
return nil return nil
@ -84,7 +45,7 @@ func BalanceRequestToGRPCMessage(b *BalanceRequest) *accounting.BalanceRequest {
BalanceRequestBodyToGRPCMessage(b.GetBody()), BalanceRequestBodyToGRPCMessage(b.GetBody()),
) )
headersToGRPC(b, m) service.RequestHeadersToGRPC(b, m)
return m return m
} }
@ -100,7 +61,7 @@ func BalanceRequestFromGRPCMessage(m *accounting.BalanceRequest) *BalanceRequest
BalanceRequestBodyFromGRPCMessage(m.GetBody()), BalanceRequestBodyFromGRPCMessage(m.GetBody()),
) )
headersFromGRPC(m, b) service.RequestHeadersFromGRPC(m, b)
return b return b
} }

View file

@ -325,3 +325,41 @@ func BearerTokenBodyFromGRPCMessage(m *service.BearerToken_Body) *BearerTokenBod
return bt 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()),
)
}