Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
09cf9b2007 | |||
996aa7a25f |
18
codec_test.go
Normal file
18
codec_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package xml
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
4
xml.go
4
xml.go
@@ -23,7 +23,7 @@ func (c *xmlCodec) Marshal(b interface{}) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (c *xmlCodec) 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 *xmlCodec) 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
|
||||
|
Reference in New Issue
Block a user