Commit 2a91439a authored by Matt Bell's avatar Matt Bell Committed by Jeromy

commands: Support outputting <-chan interface{}

parent dbaad6c1
......@@ -125,6 +125,15 @@ func (c *Command) Call(req Request) Response {
isChan = actualType.Kind() == reflect.Chan
}
if isChan {
if ch, ok := output.(<-chan interface{}); ok {
output = ch
} else if ch, ok := output.(chan interface{}); ok {
output = (<-chan interface{})(ch)
}
}
// If the command specified an output type, ensure the actual value returned is of that type
if cmd.Type != nil && !isChan {
expectedType := reflect.TypeOf(cmd.Type)
......
......@@ -167,7 +167,7 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
}
}()
res.SetOutput(outChan)
res.SetOutput((<-chan interface{})(outChan))
return res, nil
}
......
......@@ -112,6 +112,10 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// if output is a channel and user requested streaming channels,
// use chunk copier for the output
_, isChan := res.Output().(chan interface{})
if !isChan {
_, isChan = res.Output().(<-chan interface{})
}
streamChans, _, _ := req.Option("stream-channels").Bool()
if isChan && streamChans {
// w.WriteString(transferEncodingHeader + ": chunked\r\n")
......
......@@ -50,7 +50,8 @@ func marshalJson(value interface{}) (io.Reader, error) {
var marshallers = map[EncodingType]Marshaler{
JSON: func(res Response) (io.Reader, error) {
if ch, ok := res.Output().(chan interface{}); ok {
ch, ok := res.Output().(<-chan interface{})
if ok {
return &ChannelMarshaler{
Channel: ch,
Marshaler: marshalJson,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment