@cryptotaxi247 / kubo / commits / c0b28dc19

commands: Added input stream field to Request

Matt Bell committed Oct 20, 2014 at 14:38 UTC c0b28dc19dd50792aff5eec000ddb066b2fff9be
1 file changed +11 -3
commands/request.go
+11 -3
@@ -4,6 +4,7 @@ import (
4 "fmt"
5 "reflect"
6 "strconv"
7 + "io"
8 )
9
10 type optMap map[string]interface{}
@@ -14,6 +15,7 @@ type Request interface {
15 Option(name string) (interface{}, bool)
16 SetOption(name string, val interface{})
17 Arguments() []string
18 + Stream() io.Reader
19
20 ConvertOptions(options map[string]Option) error
21 }
@@ -22,6 +24,7 @@ type request struct {
24 path []string
25 options optMap
26 arguments []string
27 + in io.Reader
28 }
29
30 // Path returns the command path of this request
@@ -45,6 +48,11 @@ func (r *request) Arguments() []string {
48 return r.arguments
49 }
50
51 +// Stream returns the input stream Reader
52 +func (r *request) Stream() io.Reader {
53 + return r.in
54 +}
55 +
56 type converter func(string) (interface{}, error)
57
58 var converters = map[reflect.Kind]converter{
@@ -111,11 +119,11 @@ func (r *request) ConvertOptions(options map[string]Option) error {
119
120 // NewEmptyRequest initializes an empty request
121 func NewEmptyRequest() Request {
114 - return NewRequest(nil, nil, nil)
122 + return NewRequest(nil, nil, nil, nil)
123 }
124
125 // NewRequest returns a request initialized with given arguments
118 -func NewRequest(path []string, opts optMap, args []string) Request {
126 +func NewRequest(path []string, opts optMap, args []string, in io.Reader) Request {
127 if path == nil {
128 path = make([]string, 0)
129 }
@@ -125,5 +133,5 @@ func NewRequest(path []string, opts optMap, args []string) Request {
133 if args == nil {
134 args = make([]string, 0)
135 }
128 - return &request{path, opts, args}
136 + return &request{path, opts, args, in}
137 }