1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-11 15:15:58 +08:00

allow channel marshaler to return errors from cmds.Response

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-09-04 14:12:19 -07:00
parent 93e9f8418b
commit 206739d10c
7 changed files with 15 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import "io"
type ChannelMarshaler struct {
Channel <-chan interface{}
Marshaler func(interface{}) (io.Reader, error)
Res Response
reader io.Reader
}
@ -13,6 +14,10 @@ func (cr *ChannelMarshaler) Read(p []byte) (int, error) {
if cr.reader == nil {
val, more := <-cr.Channel
if !more {
//check error in response
if cr.Res.Error() != nil {
return 0, cr.Res.Error()
}
return 0, io.EOF
}

View File

@ -57,6 +57,7 @@ var marshallers = map[EncodingType]Marshaler{
return &ChannelMarshaler{
Channel: ch,
Marshaler: marshalJson,
Res: res,
}, nil
}