frostfs-api-go-pogpp/session/util.go
Evgenii Stratonikov 732dd51b1b [#388] *: Remove nil check from setters
I knew one day `sed` would save me an hour of manual work:
```
sed -i -n -e '
s/) Set/) Set/
p
t setter
b end
:setter
    n
    s/nil/nil/
    t hasif
    p
    b end
    :hasif
        n
        :loop
        p
        n
        s/}/}/
        t end
        b loop
        :end
' $@
goimports -w $@
```

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-03-31 11:32:04 +03:00

163 lines
3.8 KiB
Go

package session
import (
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
)
// RequestHeaders represents common part of
// all NeoFS requests including headers.
type RequestHeaders struct {
metaHeader *RequestMetaHeader
verifyHeader *RequestVerificationHeader
}
// GetMetaHeader returns meta header of the request.
func (c *RequestHeaders) GetMetaHeader() *RequestMetaHeader {
if c != nil {
return c.metaHeader
}
return nil
}
// SetMetaHeader sets meta header of the request.
func (c *RequestHeaders) SetMetaHeader(v *RequestMetaHeader) {
c.metaHeader = v
}
// GetVerificationHeader returns verification header of the request.
func (c *RequestHeaders) GetVerificationHeader() *RequestVerificationHeader {
if c != nil {
return c.verifyHeader
}
return nil
}
// SetVerificationHeader sets verification header of the request.
func (c *RequestHeaders) SetVerificationHeader(v *RequestVerificationHeader) {
c.verifyHeader = v
}
func (c *RequestHeaders) ToMessage(m interface {
SetMetaHeader(*session.RequestMetaHeader)
SetVerifyHeader(*session.RequestVerificationHeader)
}) {
m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.RequestMetaHeader))
m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.RequestVerificationHeader))
}
func (c *RequestHeaders) FromMessage(m interface {
GetMetaHeader() *session.RequestMetaHeader
GetVerifyHeader() *session.RequestVerificationHeader
}) error {
metaHdr := m.GetMetaHeader()
if metaHdr == nil {
c.metaHeader = nil
} else {
if c.metaHeader == nil {
c.metaHeader = new(RequestMetaHeader)
}
err := c.metaHeader.FromGRPCMessage(metaHdr)
if err != nil {
return err
}
}
verifyHdr := m.GetVerifyHeader()
if verifyHdr == nil {
c.verifyHeader = nil
} else {
if c.verifyHeader == nil {
c.verifyHeader = new(RequestVerificationHeader)
}
err := c.verifyHeader.FromGRPCMessage(verifyHdr)
if err != nil {
return err
}
}
return nil
}
// ResponseHeaders represents common part of
// all NeoFS responses including headers.
type ResponseHeaders struct {
metaHeader *ResponseMetaHeader
verifyHeader *ResponseVerificationHeader
}
// GetMetaHeader returns meta header of the response.
func (c *ResponseHeaders) GetMetaHeader() *ResponseMetaHeader {
if c != nil {
return c.metaHeader
}
return nil
}
// SetMetaHeader sets meta header of the response.
func (c *ResponseHeaders) SetMetaHeader(v *ResponseMetaHeader) {
c.metaHeader = v
}
// GetVerificationHeader returns verification header of the response.
func (c *ResponseHeaders) GetVerificationHeader() *ResponseVerificationHeader {
if c != nil {
return c.verifyHeader
}
return nil
}
// SetVerificationHeader sets verification header of the response.
func (c *ResponseHeaders) SetVerificationHeader(v *ResponseVerificationHeader) {
c.verifyHeader = v
}
func (c *ResponseHeaders) ToMessage(m interface {
SetMetaHeader(*session.ResponseMetaHeader)
SetVerifyHeader(*session.ResponseVerificationHeader)
}) {
m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.ResponseMetaHeader))
m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.ResponseVerificationHeader))
}
func (c *ResponseHeaders) FromMessage(m interface {
GetMetaHeader() *session.ResponseMetaHeader
GetVerifyHeader() *session.ResponseVerificationHeader
}) error {
metaHdr := m.GetMetaHeader()
if metaHdr == nil {
c.metaHeader = nil
} else {
if c.metaHeader == nil {
c.metaHeader = new(ResponseMetaHeader)
}
err := c.metaHeader.FromGRPCMessage(metaHdr)
if err != nil {
return err
}
}
verifyHdr := m.GetVerifyHeader()
if verifyHdr == nil {
c.verifyHeader = nil
} else {
if c.verifyHeader == nil {
c.verifyHeader = new(ResponseVerificationHeader)
}
err := c.verifyHeader.FromGRPCMessage(verifyHdr)
if err != nil {
return err
}
}
return nil
}