Commit 662d0e89 authored by Jan Winkelmann's avatar Jan Winkelmann

s/if elif elif elif else/type switch

parent eff7cfba
...@@ -28,33 +28,40 @@ func (rw *responseWrapper) Request() oldcmds.Request { ...@@ -28,33 +28,40 @@ func (rw *responseWrapper) Request() oldcmds.Request {
// Output returns either a <-chan interface{} on which you can receive the // Output returns either a <-chan interface{} on which you can receive the
// emitted values, or an emitted io.Reader // emitted values, or an emitted io.Reader
func (rw *responseWrapper) Output() interface{} { func (rw *responseWrapper) Output() interface{} {
log.Debug("rw.output()") log.Debugf("rw.Output: rw.Response is of type %T", rw.Response)
log.Debugf("rw.Response is of type %T", rw.Response)
//if not called before
if rw.out == nil { if rw.out == nil {
// get first emitted value
x, err := rw.Next() x, err := rw.Next()
if err != nil { if err != nil {
return nil return nil
} }
log.Debugf("next (1st) returned x=%v, err=%v; x of type %T", x, err, x) log.Debugf("next (1st) returned x=%v, err=%v; x of type %T", x, err, x)
if r, ok := x.(io.Reader); ok { switch v := x.(type) {
rw.out = r case io.Reader:
} else if ch, ok := x.(chan interface{}); ok { // if it's a reader, set it
rw.out = (<-chan interface{})(ch) rw.out = v
} else if ch, ok := x.(<-chan interface{}); ok { case chan interface{}:
rw.out = ch // if it's a chan interface, set it
} else { rw.out = (<-chan interface{})(v)
case <-chan interface{}:
// again
rw.out = v
default:
// if it is something else, create a channel and copy values from next in there
ch := make(chan interface{}) ch := make(chan interface{})
rw.out = ch rw.out = ch
go func() { go func() {
defer close(ch) defer close(ch)
ch <- x ch <- v
log.Debugf("rw.Out.go: sent %v to channel %v", x, ch) log.Debugf("rw.Out.go: sent %v to channel %v", x, ch)
for { for {
log.Debugf("rw.Out.go.for: waiting for Next()") log.Debugf("rw.Out.go.for: waiting for Next()")
x, err := rw.Next() v, err := rw.Next()
log.Debugf("next (loop) returned x=%v, err=%s; x of type %T", x, err, x) log.Debugf("next (loop) returned x=%v, err=%s; x of type %T", x, err, x)
if err == io.EOF { if err == io.EOF {
...@@ -65,8 +72,8 @@ func (rw *responseWrapper) Output() interface{} { ...@@ -65,8 +72,8 @@ func (rw *responseWrapper) Output() interface{} {
return return
} }
ch <- x ch <- v
log.Debugf("rw.Out.go.for: sent %v to channel %v", x, ch) log.Debugf("rw.Out.go.for: sent %v to channel %v", v, ch)
} }
}() }()
} }
......
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