mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 12:20:03 +08:00
commands: Added output stream field to Response
This commit is contained in:
@ -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}
|
||||
}
|
||||
|
Reference in New Issue
Block a user