From d274240d1dde406fa2cc8ac690f22c2f374b2ea2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 12 Apr 2021 16:52:10 +0300 Subject: [PATCH] dont fail empty payload Signed-off-by: Vasiliy Tolstov --- yaml.go | 3 +++ yaml_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 yaml_test.go diff --git a/yaml.go b/yaml.go index e0fead3..c3aae71 100644 --- a/yaml.go +++ b/yaml.go @@ -57,6 +57,9 @@ func (c *yamlCodec) ReadBody(conn io.Reader, b interface{}) error { buf, err := ioutil.ReadAll(conn) if err != nil { return err + } else if buf == nil { + // not needed but similar changes in all codecs + return nil } return yaml.Unmarshal(buf, b) diff --git a/yaml_test.go b/yaml_test.go new file mode 100644 index 0000000..03d1075 --- /dev/null +++ b/yaml_test.go @@ -0,0 +1,18 @@ +package yaml + +import ( + "bytes" + "testing" +) + +func TestReadBody(t *testing.T) { + s := &struct { + Name string + }{} + c := NewCodec() + b := bytes.NewReader(nil) + err := c.ReadBody(b, s) + if err != nil { + t.Fatal(err) + } +}