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
2a91439a
Commit
2a91439a
authored
Jan 20, 2015
by
Matt Bell
Committed by
Jeromy
Jan 21, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Support outputting <-chan interface{}
parent
dbaad6c1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
2 deletions
+16
-2
command.go
command.go
+9
-0
http/client.go
http/client.go
+1
-1
http/handler.go
http/handler.go
+4
-0
response.go
response.go
+2
-1
No files found.
command.go
View file @
2a91439a
...
@@ -125,6 +125,15 @@ func (c *Command) Call(req Request) Response {
...
@@ -125,6 +125,15 @@ func (c *Command) Call(req Request) Response {
isChan
=
actualType
.
Kind
()
==
reflect
.
Chan
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 the command specified an output type, ensure the actual value returned is of that type
if
cmd
.
Type
!=
nil
&&
!
isChan
{
if
cmd
.
Type
!=
nil
&&
!
isChan
{
expectedType
:=
reflect
.
TypeOf
(
cmd
.
Type
)
expectedType
:=
reflect
.
TypeOf
(
cmd
.
Type
)
...
...
http/client.go
View file @
2a91439a
...
@@ -167,7 +167,7 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
...
@@ -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
return
res
,
nil
}
}
...
...
http/handler.go
View file @
2a91439a
...
@@ -112,6 +112,10 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -112,6 +112,10 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// if output is a channel and user requested streaming channels,
// if output is a channel and user requested streaming channels,
// use chunk copier for the output
// use chunk copier for the output
_
,
isChan
:=
res
.
Output
()
.
(
chan
interface
{})
_
,
isChan
:=
res
.
Output
()
.
(
chan
interface
{})
if
!
isChan
{
_
,
isChan
=
res
.
Output
()
.
(
<-
chan
interface
{})
}
streamChans
,
_
,
_
:=
req
.
Option
(
"stream-channels"
)
.
Bool
()
streamChans
,
_
,
_
:=
req
.
Option
(
"stream-channels"
)
.
Bool
()
if
isChan
&&
streamChans
{
if
isChan
&&
streamChans
{
// w.WriteString(transferEncodingHeader + ": chunked\r\n")
// w.WriteString(transferEncodingHeader + ": chunked\r\n")
...
...
response.go
View file @
2a91439a
...
@@ -50,7 +50,8 @@ func marshalJson(value interface{}) (io.Reader, error) {
...
@@ -50,7 +50,8 @@ func marshalJson(value interface{}) (io.Reader, error) {
var
marshallers
=
map
[
EncodingType
]
Marshaler
{
var
marshallers
=
map
[
EncodingType
]
Marshaler
{
JSON
:
func
(
res
Response
)
(
io
.
Reader
,
error
)
{
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
{
return
&
ChannelMarshaler
{
Channel
:
ch
,
Channel
:
ch
,
Marshaler
:
marshalJson
,
Marshaler
:
marshalJson
,
...
...
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