fix nil buf check

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

View File

@ -23,7 +23,7 @@ func (c *yamlCodec) Marshal(b interface{}) ([]byte, error) {
} }
func (c *yamlCodec) Unmarshal(b []byte, v interface{}) error { func (c *yamlCodec) 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 *yamlCodec) 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
@ -57,7 +59,7 @@ func (c *yamlCodec) 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 buf == nil { } else if len(buf) == 0 {
// not needed but similar changes in all codecs // not needed but similar changes in all codecs
return nil return nil
} }