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-unixfs
Commits
7bd7ed6d
Commit
7bd7ed6d
authored
Oct 20, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Added output stream field to Response
parent
c0b28dc1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
commands/command.go
commands/command.go
+5
-3
commands/response.go
commands/response.go
+11
-2
No files found.
commands/command.go
View file @
7bd7ed6d
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
"io"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -46,9 +47,10 @@ func (c *Command) Register(id string, sub *Command) error {
return
nil
}
// Call invokes the command at the given subcommand path
func
(
c
*
Command
)
Call
(
req
Request
)
Response
{
res
:=
NewResponse
(
req
)
// Call invokes the command for the given Request
// Streaming output is written to `out`
func
(
c
*
Command
)
Call
(
req
Request
,
out
io
.
Writer
)
Response
{
res
:=
NewResponse
(
req
,
out
)
cmds
,
err
:=
c
.
Resolve
(
req
.
Path
())
if
err
!=
nil
{
...
...
commands/response.go
View file @
7bd7ed6d
...
...
@@ -5,6 +5,7 @@ import (
"encoding/xml"
"fmt"
"strings"
"io"
)
// ErrorType signfies a category of errors
...
...
@@ -59,6 +60,9 @@ type Response interface {
SetValue
(
interface
{})
Value
()
interface
{}
// Returns the output stream Writer
Stream
()
io
.
Writer
// Marshal marshals out the response into a buffer. It uses the EncodingType
// on the Request to chose a Marshaller (Codec).
Marshal
()
([]
byte
,
error
)
...
...
@@ -68,6 +72,7 @@ type response struct {
req
Request
err
*
Error
value
interface
{}
out
io
.
Writer
}
func
(
r
*
response
)
Request
()
Request
{
...
...
@@ -82,6 +87,10 @@ func (r *response) SetValue(v interface{}) {
r
.
value
=
v
}
func
(
r
*
response
)
Stream
()
io
.
Writer
{
return
r
.
out
}
func
(
r
*
response
)
Error
()
error
{
if
r
.
err
==
nil
{
return
nil
...
...
@@ -116,6 +125,6 @@ func (r *response) Marshal() ([]byte, error) {
}
// NewResponse returns a response to match given Request
func
NewResponse
(
req
Request
)
Response
{
return
&
response
{
req
:
req
}
func
NewResponse
(
req
Request
,
out
io
.
Writer
)
Response
{
return
&
response
{
req
:
req
,
out
:
out
}
}
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