From 74c22103001a0bf8ecd40a0ff7df66ee81c6d253 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 29 Nov 2020 21:03:18 +0300 Subject: [PATCH] tweaks Signed-off-by: Vasiliy Tolstov --- json.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/json.go b/json.go index d0d00bc..aacf20e 100644 --- a/json.go +++ b/json.go @@ -12,10 +12,9 @@ import ( type jsonCodec struct{} func (c *jsonCodec) Marshal(b interface{}) ([]byte, error) { - if b == nil { - return nil, nil - } switch m := b.(type) { + case nil: + return nil, nil case *codec.Frame: return m.Data, nil } @@ -24,10 +23,12 @@ func (c *jsonCodec) Marshal(b interface{}) ([]byte, error) { } func (c *jsonCodec) Unmarshal(b []byte, v interface{}) error { - if b == nil || v == nil { + if b == nil { return nil } switch m := v.(type) { + case nil: + return nil case *codec.Frame: m.Data = b return nil @@ -41,10 +42,9 @@ func (c *jsonCodec) ReadHeader(conn io.ReadWriter, m *codec.Message, t codec.Mes } func (c *jsonCodec) 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 { @@ -58,10 +58,9 @@ func (c *jsonCodec) ReadBody(conn io.ReadWriter, b interface{}) error { } func (c *jsonCodec) 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