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

commands: Added Context() to Request

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