Commit 7bd7ed6d authored by Matt Bell's avatar Matt Bell

commands: Added output stream field to Response

parent c0b28dc1
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"io"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
...@@ -46,9 +47,10 @@ func (c *Command) Register(id string, sub *Command) error { ...@@ -46,9 +47,10 @@ func (c *Command) Register(id string, sub *Command) error {
return nil return nil
} }
// Call invokes the command at the given subcommand path // Call invokes the command for the given Request
func (c *Command) Call(req Request) Response { // Streaming output is written to `out`
res := NewResponse(req) func (c *Command) Call(req Request, out io.Writer) Response {
res := NewResponse(req, out)
cmds, err := c.Resolve(req.Path()) cmds, err := c.Resolve(req.Path())
if err != nil { if err != nil {
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"strings" "strings"
"io"
) )
// ErrorType signfies a category of errors // ErrorType signfies a category of errors
...@@ -59,6 +60,9 @@ type Response interface { ...@@ -59,6 +60,9 @@ type Response interface {
SetValue(interface{}) SetValue(interface{})
Value() interface{} Value() interface{}
// Returns the output stream Writer
Stream() io.Writer
// Marshal marshals out the response into a buffer. It uses the EncodingType // Marshal marshals out the response into a buffer. It uses the EncodingType
// on the Request to chose a Marshaller (Codec). // on the Request to chose a Marshaller (Codec).
Marshal() ([]byte, error) Marshal() ([]byte, error)
...@@ -68,6 +72,7 @@ type response struct { ...@@ -68,6 +72,7 @@ type response struct {
req Request req Request
err *Error err *Error
value interface{} value interface{}
out io.Writer
} }
func (r *response) Request() Request { func (r *response) Request() Request {
...@@ -82,6 +87,10 @@ func (r *response) SetValue(v interface{}) { ...@@ -82,6 +87,10 @@ func (r *response) SetValue(v interface{}) {
r.value = v r.value = v
} }
func (r *response) Stream() io.Writer {
return r.out
}
func (r *response) Error() error { func (r *response) Error() error {
if r.err == nil { if r.err == nil {
return nil return nil
...@@ -116,6 +125,6 @@ func (r *response) Marshal() ([]byte, error) { ...@@ -116,6 +125,6 @@ func (r *response) Marshal() ([]byte, error) {
} }
// NewResponse returns a response to match given Request // NewResponse returns a response to match given Request
func NewResponse(req Request) Response { func NewResponse(req Request, out io.Writer) Response {
return &response{req: req} return &response{req: req, out: out}
} }
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