Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
662d0e89
Commit
662d0e89
authored
Apr 05, 2017
by
Jan Winkelmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
s/if elif elif elif else/type switch
parent
eff7cfba
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
legacy.go
legacy.go
+20
-13
No files found.
legacy.go
View file @
662d0e89
...
...
@@ -28,33 +28,40 @@ func (rw *responseWrapper) Request() oldcmds.Request {
// Output returns either a <-chan interface{} on which you can receive the
// emitted values, or an emitted io.Reader
func
(
rw
*
responseWrapper
)
Output
()
interface
{}
{
log
.
Debug
(
"rw.output()"
)
log
.
Debugf
(
"rw.Response is of type %T"
,
rw
.
Response
)
log
.
Debugf
(
"rw.Output: rw.Response is of type %T"
,
rw
.
Response
)
//if not called before
if
rw
.
out
==
nil
{
// get first emitted value
x
,
err
:=
rw
.
Next
()
if
err
!=
nil
{
return
nil
}
log
.
Debugf
(
"next (1st) returned x=%v, err=%v; x of type %T"
,
x
,
err
,
x
)
if
r
,
ok
:=
x
.
(
io
.
Reader
);
ok
{
rw
.
out
=
r
}
else
if
ch
,
ok
:=
x
.
(
chan
interface
{});
ok
{
rw
.
out
=
(
<-
chan
interface
{})(
ch
)
}
else
if
ch
,
ok
:=
x
.
(
<-
chan
interface
{});
ok
{
rw
.
out
=
ch
}
else
{
switch
v
:=
x
.
(
type
)
{
case
io
.
Reader
:
// if it's a reader, set it
rw
.
out
=
v
case
chan
interface
{}
:
// if it's a chan interface, set it
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
{})
rw
.
out
=
ch
go
func
()
{
defer
close
(
ch
)
ch
<-
x
ch
<-
v
log
.
Debugf
(
"rw.Out.go: sent %v to channel %v"
,
x
,
ch
)
for
{
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
)
if
err
==
io
.
EOF
{
...
...
@@ -65,8 +72,8 @@ func (rw *responseWrapper) Output() interface{} {
return
}
ch
<-
x
log
.
Debugf
(
"rw.Out.go.for: sent %v to channel %v"
,
x
,
ch
)
ch
<-
v
log
.
Debugf
(
"rw.Out.go.for: sent %v to channel %v"
,
v
,
ch
)
}
}()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment