提交 20f86c01 作者: Matt Bell 提交者: Juan Batiz-Benet

commands: Added Context() to Request

上级 b033e332
...@@ -5,10 +5,19 @@ import ( ...@@ -5,10 +5,19 @@ import (
"io" "io"
"reflect" "reflect"
"strconv" "strconv"
"github.com/jbenet/go-ipfs/config"
"github.com/jbenet/go-ipfs/core"
) )
type optMap map[string]interface{} type optMap map[string]interface{}
type Context struct {
ConfigRoot string
Config *config.Config
Node *core.IpfsNode
}
// Request represents a call to a command from a consumer // Request represents a call to a command from a consumer
type Request interface { type Request interface {
Path() []string Path() []string
...@@ -18,6 +27,7 @@ type Request interface { ...@@ -18,6 +27,7 @@ type Request interface {
Arguments() []string Arguments() []string
Stream() io.Reader Stream() io.Reader
SetStream(io.Reader) SetStream(io.Reader)
Context() *Context
ConvertOptions(options map[string]Option) error ConvertOptions(options map[string]Option) error
} }
...@@ -27,6 +37,7 @@ type request struct { ...@@ -27,6 +37,7 @@ type request struct {
options optMap options optMap
arguments []string arguments []string
in io.Reader in io.Reader
ctx Context
} }
// Path returns the command path of this request // Path returns the command path of this request
...@@ -69,6 +80,10 @@ func (r *request) SetStream(in io.Reader) { ...@@ -69,6 +80,10 @@ func (r *request) SetStream(in io.Reader) {
r.in = in r.in = in
} }
func (r *request) Context() *Context {
return &r.ctx
}
type converter func(string) (interface{}, error) type converter func(string) (interface{}, error)
var converters = map[reflect.Kind]converter{ var converters = map[reflect.Kind]converter{
...@@ -149,5 +164,5 @@ func NewRequest(path []string, opts optMap, args []string, in io.Reader) Request ...@@ -149,5 +164,5 @@ func NewRequest(path []string, opts optMap, args []string, in io.Reader) Request
if args == nil { if args == nil {
args = make([]string, 0) args = make([]string, 0)
} }
return &request{path, opts, args, in} return &request{path, opts, args, in, Context{}}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论