From 012d8c3fcb03c56d9d54b3c882761e439d1e523e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 29 Nov 2020 21:06:14 +0300 Subject: [PATCH] tweaks Signed-off-by: Vasiliy Tolstov --- proto.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/proto.go b/proto.go index 3507f88..eea6301 100644 --- a/proto.go +++ b/proto.go @@ -5,6 +5,7 @@ import ( "io" "io/ioutil" + // nolint: staticcheck oldproto "github.com/golang/protobuf/proto" "github.com/unistack-org/micro/v3/codec" "google.golang.org/protobuf/proto" @@ -13,10 +14,9 @@ import ( type protoCodec struct{} func (c *protoCodec) Marshal(v interface{}) ([]byte, error) { - if v == nil { - return nil, nil - } switch m := v.(type) { + case nil: + return nil, nil case *codec.Frame: return m.Data, nil case proto.Message: @@ -28,10 +28,12 @@ func (c *protoCodec) Marshal(v interface{}) ([]byte, error) { } func (c *protoCodec) Unmarshal(d []byte, v interface{}) error { - if d == nil || v == nil { + if d == nil { return nil } switch m := v.(type) { + case nil: + return nil case *codec.Frame: m.Data = d case proto.Message: @@ -47,10 +49,9 @@ func (c *protoCodec) ReadHeader(conn io.ReadWriter, m *codec.Message, t codec.Me } func (c *protoCodec) ReadBody(conn io.ReadWriter, b interface{}) error { - if b == nil { - return nil - } switch m := b.(type) { + case nil: + return nil case *codec.Frame: buf, err := ioutil.ReadAll(conn) if err != nil { @@ -75,10 +76,9 @@ func (c *protoCodec) ReadBody(conn io.ReadWriter, b interface{}) error { } func (c *protoCodec) Write(conn io.ReadWriter, m *codec.Message, b interface{}) error { - if b == nil { - return nil - } switch m := b.(type) { + case nil: + return nil case *codec.Frame: _, err := conn.Write(m.Data) return err