mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 12:27:43 +08:00
commands: Added input stream field to Request
This commit is contained in:
parent
b10fc2cc50
commit
c0b28dc19d
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"io"
|
||||
)
|
||||
|
||||
type optMap map[string]interface{}
|
||||
@ -14,6 +15,7 @@ type Request interface {
|
||||
Option(name string) (interface{}, bool)
|
||||
SetOption(name string, val interface{})
|
||||
Arguments() []string
|
||||
Stream() io.Reader
|
||||
|
||||
ConvertOptions(options map[string]Option) error
|
||||
}
|
||||
@ -22,6 +24,7 @@ type request struct {
|
||||
path []string
|
||||
options optMap
|
||||
arguments []string
|
||||
in io.Reader
|
||||
}
|
||||
|
||||
// Path returns the command path of this request
|
||||
@ -45,6 +48,11 @@ func (r *request) Arguments() []string {
|
||||
return r.arguments
|
||||
}
|
||||
|
||||
// Stream returns the input stream Reader
|
||||
func (r *request) Stream() io.Reader {
|
||||
return r.in
|
||||
}
|
||||
|
||||
type converter func(string) (interface{}, error)
|
||||
|
||||
var converters = map[reflect.Kind]converter{
|
||||
@ -111,11 +119,11 @@ func (r *request) ConvertOptions(options map[string]Option) error {
|
||||
|
||||
// NewEmptyRequest initializes an empty request
|
||||
func NewEmptyRequest() Request {
|
||||
return NewRequest(nil, nil, nil)
|
||||
return NewRequest(nil, nil, nil, nil)
|
||||
}
|
||||
|
||||
// NewRequest returns a request initialized with given arguments
|
||||
func NewRequest(path []string, opts optMap, args []string) Request {
|
||||
func NewRequest(path []string, opts optMap, args []string, in io.Reader) Request {
|
||||
if path == nil {
|
||||
path = make([]string, 0)
|
||||
}
|
||||
@ -125,5 +133,5 @@ func NewRequest(path []string, opts optMap, args []string) Request {
|
||||
if args == nil {
|
||||
args = make([]string, 0)
|
||||
}
|
||||
return &request{path, opts, args}
|
||||
return &request{path, opts, args, in}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user