Commit 3a00a232 authored by Jan Winkelmann's avatar Jan Winkelmann

extract opts, args and helptext to cmdsutils subpackage

this way we can share the code with the legace commands package and don't have to convert everything
parent 2422ada8
......@@ -3,6 +3,8 @@ package cmds
import (
"fmt"
"io"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
)
func NewChanResponsePair(req *Request) (ResponseEmitter, Response) {
......@@ -25,7 +27,7 @@ func NewChanResponsePair(req *Request) (ResponseEmitter, Response) {
type chanResponse struct {
req *Request
err *Error
err *cmdsutil.Error
length uint64
ch <-chan interface{}
......@@ -35,7 +37,7 @@ func (r *chanResponse) Request() *Request {
return r.req
}
func (r *chanResponse) Error() *Error {
func (r *chanResponse) Error() *cmdsutil.Error {
return r.err
}
......@@ -56,18 +58,18 @@ type chanResponseEmitter struct {
ch chan<- interface{}
length *uint64
err **Error
err **cmdsutil.Error
emitted bool
}
func (re *chanResponseEmitter) SetError(err interface{}, t ErrorType) {
func (re *chanResponseEmitter) SetError(err interface{}, t cmdsutil.ErrorType) {
// don't change value after emitting
if re.emitted {
return
}
*re.err = &Error{Message: fmt.Sprint(err), Code: t}
*re.err = &cmdsutil.Error{Message: fmt.Sprint(err), Code: t}
}
func (re *chanResponseEmitter) SetLength(l uint64) {
......
package cmds
/*
import "io"
type ChannelMarshaler struct {
......@@ -37,3 +38,4 @@ func (cr *ChannelMarshaler) Read(p []byte) (int, error) {
}
return n, nil
}
*/
package cmds
package cmdsutil
type ArgumentType int
......
package cmds
package cmdsutil
// ErrorType signfies a category of errors
type ErrorType uint
......
package cmdsutil
// HelpText is a set of strings used to generate command help text. The help
// text follows formats similar to man pages, but not exactly the same.
type HelpText struct {
// required
Tagline string // used in <cmd usage>
ShortDescription string // used in DESCRIPTION
SynopsisOptionsValues map[string]string // mappings for synopsis generator
// optional - whole section overrides
Usage string // overrides USAGE section
LongDescription string // overrides DESCRIPTION section
Options string // overrides OPTIONS section
Arguments string // overrides ARGUMENTS section
Subcommands string // overrides SUBCOMMANDS section
Synopsis string // overrides SYNOPSIS field
}
package cmds
package cmdsutil
import (
"fmt"
......@@ -18,6 +18,8 @@ const (
String = reflect.String
)
type OptMap map[string]interface{}
// Option is used to specify a field that will be provided by a consumer
type Option interface {
Names() []string // a list of unique names matched with user-provided flags
......@@ -109,75 +111,75 @@ func StringOption(names ...string) Option {
}
type OptionValue struct {
value interface{}
found bool
def Option
Value interface{}
ValueFound bool
Def Option
}
// Found returns true if the option value was provided by the user (not a default value)
func (ov OptionValue) Found() bool {
return ov.found
return ov.ValueFound
}
// Definition returns the option definition for the provided value
func (ov OptionValue) Definition() Option {
return ov.def
return ov.Def
}
// value accessor methods, gets the value as a certain type
func (ov OptionValue) Bool() (value bool, found bool, err error) {
if !ov.found && ov.value == nil {
if !ov.ValueFound && ov.Value == nil {
return false, false, nil
}
val, ok := ov.value.(bool)
val, ok := ov.Value.(bool)
if !ok {
err = util.ErrCast()
}
return val, ov.found, err
return val, ov.ValueFound, err
}
func (ov OptionValue) Int() (value int, found bool, err error) {
if !ov.found && ov.value == nil {
if !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.value.(int)
val, ok := ov.Value.(int)
if !ok {
err = util.ErrCast()
}
return val, ov.found, err
return val, ov.ValueFound, err
}
func (ov OptionValue) Uint() (value uint, found bool, err error) {
if !ov.found && ov.value == nil {
if !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.value.(uint)
val, ok := ov.Value.(uint)
if !ok {
err = util.ErrCast()
}
return val, ov.found, err
return val, ov.ValueFound, err
}
func (ov OptionValue) Float() (value float64, found bool, err error) {
if !ov.found && ov.value == nil {
if !ov.ValueFound && ov.Value == nil {
return 0, false, nil
}
val, ok := ov.value.(float64)
val, ok := ov.Value.(float64)
if !ok {
err = util.ErrCast()
}
return val, ov.found, err
return val, ov.ValueFound, err
}
func (ov OptionValue) String() (value string, found bool, err error) {
if !ov.found && ov.value == nil {
if !ov.ValueFound && ov.Value == nil {
return "", false, nil
}
val, ok := ov.value.(string)
val, ok := ov.Value.(string)
if !ok {
err = util.ErrCast()
}
return val, ov.found, err
return val, ov.ValueFound, err
}
// Flag names
......@@ -195,15 +197,3 @@ var OptionEncodingType = StringOption(EncLong, EncShort, "The encoding type the
var OptionRecursivePath = BoolOption(RecLong, RecShort, "Add directory paths recursively").Default(false)
var OptionStreamChannels = BoolOption(ChanOpt, "Stream channel output")
var OptionTimeout = StringOption(TimeoutOpt, "set a global timeout on the command")
// global options, added to every command
var globalOptions = []Option{
OptionEncodingType,
OptionStreamChannels,
OptionTimeout,
}
// the above array of Options, wrapped in a Command
var globalCommand = &Command{
Options: globalOptions,
}
package cmds
package cmdsutil
import (
"strings"
......
......@@ -13,6 +13,8 @@ import (
"fmt"
"reflect"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
oldcmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/path"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
......@@ -24,28 +26,11 @@ var log = logging.Logger("command")
// It reads from the Request, and writes results to the ResponseEmitter.
type Function func(Request, ResponseEmitter)
// HelpText is a set of strings used to generate command help text. The help
// text follows formats similar to man pages, but not exactly the same.
type HelpText struct {
// required
Tagline string // used in <cmd usage>
ShortDescription string // used in DESCRIPTION
SynopsisOptionsValues map[string]string // mappings for synopsis generator
// optional - whole section overrides
Usage string // overrides USAGE section
LongDescription string // overrides DESCRIPTION section
Options string // overrides OPTIONS section
Arguments string // overrides ARGUMENTS section
Subcommands string // overrides SUBCOMMANDS section
Synopsis string // overrides SYNOPSIS field
}
// Command is a runnable command, with input arguments and options (flags).
// It can also have Subcommands, to group units of work into sets.
type Command struct {
Options []Option
Arguments []Argument
Options []cmdsutil.Option
Arguments []cmdsutil.Argument
PreRun func(req Request) error
// Run is the function that processes the request to generate a response.
......@@ -55,7 +40,7 @@ type Command struct {
Run interface{}
PostRun interface{}
Encoders map[EncodingType]Encoder
Helptext HelpText
Helptext cmdsutil.HelpText
// External denotes that a command is actually an external binary.
// fewer checks and validations will be performed on such commands.
......@@ -170,7 +155,7 @@ func (c *Command) Call(req Request, re ResponseEmitter) error {
} else if ch, ok := output.(chan interface{}); ok {
output = (<-chan interface{})(ch)
} else {
re.SetError(ErrIncorrectType, ErrNormal)
re.SetError(ErrIncorrectType, cmdsutil.ErrNormal)
return ErrIncorrectType
}
......@@ -186,7 +171,7 @@ func (c *Command) Call(req Request, re ResponseEmitter) error {
expectedType := reflect.TypeOf(cmd.Type)
if actualType != expectedType {
re.SetError(ErrIncorrectType, ErrNormal)
re.SetError(ErrIncorrectType, cmdsutil.ErrNormal)
return ErrIncorrectType
}
}
......@@ -195,6 +180,7 @@ func (c *Command) Call(req Request, re ResponseEmitter) error {
}
return nil
}
// Resolve returns the subcommands at the given path
......@@ -227,8 +213,8 @@ func (c *Command) Get(path []string) (*Command, error) {
}
// GetOptions returns the options in the given path of commands
func (c *Command) GetOptions(path []string) (map[string]Option, error) {
options := make([]Option, 0, len(c.Options))
func (c *Command) GetOptions(path []string) (map[string]cmdsutil.Option, error) {
options := make([]cmdsutil.Option, 0, len(c.Options))
cmds, err := c.Resolve(path)
if err != nil {
......@@ -240,7 +226,7 @@ func (c *Command) GetOptions(path []string) (map[string]Option, error) {
options = append(options, cmd.Options...)
}
optionsMap := make(map[string]Option)
optionsMap := make(map[string]cmdsutil.Option)
for _, opt := range options {
for _, name := range opt.Names() {
if _, found := optionsMap[name]; found {
......@@ -271,7 +257,7 @@ func (c *Command) CheckArguments(req Request) error {
// skip optional argument definitions if there aren't
// sufficient remaining values
if len(args)-valueIndex <= numRequired && !argDef.Required ||
argDef.Type == ArgFile {
argDef.Type == cmdsutil.ArgFile {
continue
}
......@@ -334,7 +320,7 @@ func (c *Command) ProcessHelp() {
// checkArgValue returns an error if a given arg value is not valid for the
// given Argument
func checkArgValue(v string, found bool, def Argument) error {
func checkArgValue(v string, found bool, def cmdsutil.Argument) error {
if def.Variadic && def.SupportsStdin {
return nil
}
......@@ -347,5 +333,17 @@ func checkArgValue(v string, found bool, def Argument) error {
}
func ClientError(msg string) error {
return &Error{Code: ErrClient, Message: msg}
return &cmdsutil.Error{Code: cmdsutil.ErrClient, Message: msg}
}
// global options, added to every command
var globalOptions = []cmdsutil.Option{
cmdsutil.OptionEncodingType,
cmdsutil.OptionStreamChannels,
cmdsutil.OptionTimeout,
}
// the above array of Options, wrapped in a Command
var globalCommand = &Command{
Options: globalOptions,
}
......@@ -12,7 +12,8 @@ import (
"strconv"
"strings"
cmds "github.com/ipfs/go-ipfs/commands"
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
config "github.com/ipfs/go-ipfs/repo/config"
context "context"
......@@ -54,16 +55,16 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
}
// save user-provided encoding
previousUserProvidedEncoding, found, err := req.Option(cmds.EncShort).String()
previousUserProvidedEncoding, found, err := req.Option(cmdsutil.EncShort).String()
if err != nil {
return nil, err
}
// override with json to send to server
req.SetOption(cmds.EncShort, cmds.JSON)
req.SetOption(cmdsutil.EncShort, cmds.JSON)
// stream channel output
req.SetOption(cmds.ChanOpt, "true")
req.SetOption(cmdsutil.ChanOpt, "true")
query, err := getQuery(req)
if err != nil {
......@@ -112,7 +113,7 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
// reset to user provided encoding after sending request
// NB: if user has provided an encoding but it is the empty string,
// still leave it as JSON.
req.SetOption(cmds.EncShort, previousUserProvidedEncoding)
req.SetOption(cmdsutil.EncShort, previousUserProvidedEncoding)
}
return res, nil
......@@ -136,7 +137,7 @@ func getQuery(req cmds.Request) (string, error) {
for _, arg := range args {
argDef := argDefs[argDefIndex]
// skip ArgFiles
for argDef.Type == cmds.ArgFile {
for argDef.Type == cmdsutil.ArgFile {
argDefIndex++
argDef = argDefs[argDefIndex]
}
......
......@@ -13,7 +13,9 @@ import (
"github.com/ipfs/go-ipfs/repo/config"
cors "gx/ipfs/QmQzTLDsi3a37CJyMDBXnjiHKQpth3AGS1yqwU57FfLwfG/cors"
cmds "github.com/ipfs/go-ipfs/commands"
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
)
......@@ -162,6 +164,7 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err == ErrNotFound {
w.WriteHeader(http.StatusNotFound)
} else {
w.WriteHeader(http.StatusBadRequest)
}
w.Write([]byte(err.Error()))
......@@ -190,7 +193,7 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
enc := cmds.EncodingType(req.Options()[cmds.EncShort].(string))
enc := cmds.EncodingType(req.Options()[cmdsutil.EncShort].(string))
re := NewResponseEmitter(w, enc, r.Method)
// call the command
......
......@@ -9,7 +9,7 @@ import (
"net/url"
"sync"
files "github.com/ipfs/go-ipfs/commands/files"
files "github.com/ipfs/go-ipfs-cmds/files"
)
// MultiFileReader reads from a `commands.File` (which can be a directory of files
......
......@@ -7,7 +7,7 @@ import (
"strings"
"testing"
files "github.com/ipfs/go-ipfs/commands/files"
files "github.com/ipfs/go-ipfs-cmds/files"
)
func TestOutput(t *testing.T) {
......
......@@ -7,8 +7,9 @@ import (
"net/http"
"strings"
cmds "github.com/ipfs/go-ipfs/commands"
files "github.com/ipfs/go-ipfs/commands/files"
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
"github.com/ipfs/go-ipfs-cmds/files"
path "github.com/ipfs/go-ipfs/path"
)
......@@ -74,7 +75,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
numRequired--
}
if argDef.Type == cmds.ArgString {
if argDef.Type == cmdsutil.ArgString {
if argDef.Variadic {
for _, s := range stringArgs {
args[valIndex] = s
......@@ -90,7 +91,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
} else {
break
}
} else if argDef.Type == cmds.ArgFile && argDef.Required && len(requiredFile) == 0 {
} else if argDef.Type == cmdsutil.ArgFile && argDef.Required && len(requiredFile) == 0 {
requiredFile = argDef.Name
}
}
......@@ -149,10 +150,10 @@ func parseOptions(r *http.Request) (map[string]interface{}, []string) {
}
// default to setting encoding to JSON
_, short := opts[cmds.EncShort]
_, long := opts[cmds.EncLong]
_, short := opts[cmdsutil.EncShort]
_, long := opts[cmdsutil.EncLong]
if !short && !long {
opts[cmds.EncShort] = cmds.JSON
opts[cmdsutil.EncShort] = cmds.JSON
}
return opts, args
......
......@@ -7,7 +7,9 @@ import (
"os"
"strconv"
cmds "github.com/ipfs/go-ipfs/commands"
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
"github.com/ipfs/go-ipfs/repo/config"
)
......@@ -33,7 +35,7 @@ type ResponseEmitter struct {
encType cmds.EncodingType
length uint64
err *Error
err *cmdsutil.Error
hasEmitted bool
method string
......@@ -82,8 +84,8 @@ func (re *ResponseEmitter) Close() error {
return nil
}
func (re *ResponseEmitter) SetError(err interface{}, code cmds.ErrorType) {
re.err = &cmds.Error{Message: fmt.Sprint(err), Code: code}
func (re *ResponseEmitter) SetError(err interface{}, code cmdsutil.ErrorType) {
re.err = &cmdsutil.Error{Message: fmt.Sprint(err), Code: code}
// force send of preamble
// TODO is this the right thing to do?
......@@ -108,7 +110,7 @@ func (re *ResponseEmitter) preamble(value interface{}) {
status := http.StatusOK
// if response contains an error, write an HTTP error status code
if e := re.err; e != nil {
if e.(cmds.Error).Code == cmds.ErrClient {
if e.Code == cmdsutil.ErrClient {
status = http.StatusBadRequest
} else {
status = http.StatusInternalServerError
......@@ -118,8 +120,8 @@ func (re *ResponseEmitter) preamble(value interface{}) {
// write error to connection
if re.err != nil {
if re.err.Code == ErrClient {
http.Error(re.w, err.Error(), http.StatusInternalServerError)
if re.err.Code == cmdsutil.ErrClient {
http.Error(re.w, re.err.Error(), http.StatusInternalServerError)
}
return
......
......@@ -2,6 +2,7 @@ package cmds
import (
"bufio"
"context"
"errors"
"fmt"
"io"
......@@ -10,9 +11,9 @@ import (
"strconv"
"time"
context "context"
// oldcmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/commands/files"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
"github.com/ipfs/go-ipfs-cmds/files"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/repo/config"
u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
......@@ -67,10 +68,10 @@ func (c *Context) NodeWithoutConstructing() *core.IpfsNode {
// Request represents a call to a command from a consumer
type Request interface {
Path() []string
Option(name string) *OptionValue
Options() OptMap
Option(name string) *cmdsutil.OptionValue
Options() cmdsutil.OptMap
SetOption(name string, val interface{})
SetOptions(opts OptMap) error
SetOptions(opts cmdsutil.OptMap) error
Arguments() []string
StringArguments() []string
SetArguments([]string)
......@@ -90,13 +91,13 @@ type Request interface {
type request struct {
path []string
options OptMap
options cmdsutil.OptMap
arguments []string
files files.File
cmd *Command
ctx Context
rctx context.Context
optionDefs map[string]Option
optionDefs map[string]cmdsutil.Option
values map[string]interface{}
stdin io.Reader
}
......@@ -107,7 +108,7 @@ func (r *request) Path() []string {
}
// Option returns the value of the option for given name.
func (r *request) Option(name string) *OptionValue {
func (r *request) Option(name string) *cmdsutil.OptionValue {
// find the option with the specified name
option, found := r.optionDefs[name]
if !found {
......@@ -118,16 +119,16 @@ func (r *request) Option(name string) *OptionValue {
for _, n := range option.Names() {
val, found := r.options[n]
if found {
return &OptionValue{val, found, option}
return &cmdsutil.OptionValue{val, found, option}
}
}
return &OptionValue{option.DefaultVal(), false, option}
return &cmdsutil.OptionValue{option.DefaultVal(), false, option}
}
// Options returns a copy of the option map
func (r *request) Options() OptMap {
output := make(OptMap)
func (r *request) Options() cmdsutil.OptMap {
output := make(cmdsutil.OptMap)
for k, v := range r.options {
output[k] = v
}
......@@ -165,7 +166,7 @@ func (r *request) SetOption(name string, val interface{}) {
}
// SetOptions sets the option values, unsetting any values that were previously set
func (r *request) SetOptions(opts OptMap) error {
func (r *request) SetOptions(opts cmdsutil.OptMap) error {
r.options = opts
return r.ConvertOptions()
}
......@@ -213,7 +214,7 @@ func (r *request) haveVarArgsFromStdin() bool {
}
last := r.cmd.Arguments[len(r.cmd.Arguments)-1]
return last.SupportsStdin && last.Type == ArgString && (last.Required || last.Variadic) &&
return last.SupportsStdin && last.Type == cmdsutil.ArgString && (last.Required || last.Variadic) &&
len(r.arguments) < len(r.cmd.Arguments)
}
......@@ -294,27 +295,27 @@ func (r *request) Command() *Command {
type converter func(string) (interface{}, error)
var converters = map[reflect.Kind]converter{
Bool: func(v string) (interface{}, error) {
cmdsutil.Bool: func(v string) (interface{}, error) {
if v == "" {
return true, nil
}
return strconv.ParseBool(v)
},
Int: func(v string) (interface{}, error) {
cmdsutil.Int: func(v string) (interface{}, error) {
val, err := strconv.ParseInt(v, 0, 32)
if err != nil {
return nil, err
}
return int(val), err
},
Uint: func(v string) (interface{}, error) {
cmdsutil.Uint: func(v string) (interface{}, error) {
val, err := strconv.ParseUint(v, 0, 32)
if err != nil {
return nil, err
}
return int(val), err
},
Float: func(v string) (interface{}, error) {
cmdsutil.Float: func(v string) (interface{}, error) {
return strconv.ParseFloat(v, 64)
},
}
......@@ -336,7 +337,7 @@ func (r *request) ConvertOptions() error {
kind := reflect.TypeOf(v).Kind()
if kind != opt.Type() {
if kind == String {
if kind == cmdsutil.String {
convert := converters[opt.Type()]
str, ok := v.(string)
if !ok {
......@@ -379,12 +380,12 @@ func NewEmptyRequest() (Request, error) {
// NewRequest returns a request initialized with given arguments
// An non-nil error will be returned if the provided option values are invalid
func NewRequest(path []string, opts OptMap, args []string, file files.File, cmd *Command, optDefs map[string]Option) (Request, error) {
func NewRequest(path []string, opts cmdsutil.OptMap, args []string, file files.File, cmd *Command, optDefs map[string]cmdsutil.Option) (Request, error) {
if opts == nil {
opts = make(OptMap)
opts = make(cmdsutil.OptMap)
}
if optDefs == nil {
optDefs = make(map[string]Option)
optDefs = make(map[string]cmdsutil.Option)
}
ctx := Context{}
......
......@@ -4,7 +4,7 @@ import (
"io"
"os"
oldcmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
)
// Response is the result of a command request. Response is returned to the client.
......@@ -12,7 +12,7 @@ type Response interface {
// TODO should be drop that?
Request() *Request
Error() *Error
Error() *cmdsutil.Error
Length() uint64
Next() (interface{}, error)
......
......@@ -2,6 +2,8 @@ package cmds
import (
"io"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
)
// ResponseEmitter encodes and sends the command code's output to the client.
......@@ -16,7 +18,7 @@ type ResponseEmitter interface {
// SetError sets the response error
// err is an interface{} so we don't have to manually convert to error.
SetError(err interface{}, code ErrorType)
SetError(err interface{}, code cmdsutil.ErrorType)
// Gets Stdout and Stderr, for writing to console without using SetOutput
// TODO I'm not sure we really need that, but lets see
......
package cmds
import (
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
)
// NewTeeEmitter creates a new ResponseEmitter.
// Writing to it will write to both the passed ResponseEmitters.
func NewTeeEmitter(re1, re2 ResponseEmitter) ResponseEmitter {
......@@ -41,7 +45,7 @@ func (re *teeEmitter) SetLength(l uint64) {
re.re.SetLength(l)
}
func (re *teeEmitter) SetError(err interface{}, code ErrorType) {
func (re *teeEmitter) SetError(err interface{}, code cmdsutil.ErrorType) {
re.ResponseEmitter.SetError(err, code)
re.re.SetError(err, code)
}
......@@ -4,6 +4,8 @@ import (
"fmt"
"io"
"reflect"
"github.com/ipfs/go-ipfs-cmds/cmdsutil"
)
func NewPipeResponsePair(encType EncodingType, req Request) (ResponseEmitter, Response) {
......@@ -42,14 +44,14 @@ type readerResponse struct {
t reflect.Type
length uint64
err *Error
err *cmdsutil.Error
}
func (r *readerResponse) Request() *Request {
return &r.req
}
func (r *readerResponse) Error() *Error {
func (r *readerResponse) Error() *cmdsutil.Error {
return r.err
}
......@@ -70,17 +72,17 @@ type writerResponseEmitter struct {
enc Encoder
length *uint64
err *Error
err *cmdsutil.Error
emitted bool
}
func (re *writerResponseEmitter) SetError(err interface{}, code ErrorType) {
func (re *writerResponseEmitter) SetError(err interface{}, code cmdsutil.ErrorType) {
if re.emitted {
return
}
*re.err = Error{Message: fmt.Sprint(err), Code: code}
*re.err = cmdsutil.Error{Message: fmt.Sprint(err), Code: code}
}
func (re *writerResponseEmitter) SetLength(length uint64) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment