fix nil buf check

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-04-12 19:12:16 +03:00
parent b7f6b22fb2
commit af19b4f2e7

View File

@ -23,7 +23,7 @@ func (c *jsonCodec) Marshal(b interface{}) ([]byte, error) {
} }
func (c *jsonCodec) Unmarshal(b []byte, v interface{}) error { func (c *jsonCodec) Unmarshal(b []byte, v interface{}) error {
if b == nil { if len(b) == 0 {
return nil return nil
} }
switch m := v.(type) { switch m := v.(type) {
@ -49,6 +49,8 @@ func (c *jsonCodec) ReadBody(conn io.Reader, b interface{}) error {
buf, err := ioutil.ReadAll(conn) buf, err := ioutil.ReadAll(conn)
if err != nil { if err != nil {
return err return err
} else if len(buf) == 0 {
return nil
} }
m.Data = buf m.Data = buf
return nil return nil