From af19b4f2e779f11dd7a423b5d3eddb325bf58b86 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 12 Apr 2021 19:12:16 +0300 Subject: [PATCH] fix nil buf check Signed-off-by: Vasiliy Tolstov --- json.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/json.go b/json.go index 49c630d..0906cd5 100644 --- a/json.go +++ b/json.go @@ -23,7 +23,7 @@ func (c *jsonCodec) Marshal(b interface{}) ([]byte, error) { } func (c *jsonCodec) Unmarshal(b []byte, v interface{}) error { - if b == nil { + if len(b) == 0 { return nil } switch m := v.(type) { @@ -49,6 +49,8 @@ func (c *jsonCodec) ReadBody(conn io.Reader, b interface{}) error { buf, err := ioutil.ReadAll(conn) if err != nil { return err + } else if len(buf) == 0 { + return nil } m.Data = buf return nil