@cryptotaxi247 / kubo / commits / 20f86c01c

commands: Added Context() to Request

Matt Bell committed Oct 27, 2014 at 17:30 UTC 20f86c01ce767df6ccfc4080dfab56f8e3b64912
1 file changed +16 -1
commands/request.go
+16 -1
@@ -5,10 +5,19 @@ import (
5 "io"
6 "reflect"
7 "strconv"
8 +
9 + "github.com/jbenet/go-ipfs/config"
10 + "github.com/jbenet/go-ipfs/core"
11 )
12
13 type optMap map[string]interface{}
14
15 +type Context struct {
16 + ConfigRoot string
17 + Config *config.Config
18 + Node *core.IpfsNode
19 +}
20 +
21 // Request represents a call to a command from a consumer
22 type Request interface {
23 Path() []string
@@ -18,6 +27,7 @@ type Request interface {
27 Arguments() []string
28 Stream() io.Reader
29 SetStream(io.Reader)
30 + Context() *Context
31
32 ConvertOptions(options map[string]Option) error
33 }
@@ -27,6 +37,7 @@ type request struct {
37 options optMap
38 arguments []string
39 in io.Reader
40 + ctx Context
41 }
42
43 // Path returns the command path of this request
@@ -69,6 +80,10 @@ func (r *request) SetStream(in io.Reader) {
80 r.in = in
81 }
82
83 +func (r *request) Context() *Context {
84 + return &r.ctx
85 +}
86 +
87 type converter func(string) (interface{}, error)
88
89 var converters = map[reflect.Kind]converter{
@@ -149,5 +164,5 @@ func NewRequest(path []string, opts optMap, args []string, in io.Reader) Request
164 if args == nil {
165 args = make([]string, 0)
166 }
152 - return &request{path, opts, args, in}
167 + return &request{path, opts, args, in, Context{}}
168 }