1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-10-16 19:24:02 +08:00
Files
kubo/commands/response.go
Steven Allen 85acad9a01 gx update go-log, sys, go-crypto
* go-log
* sys
* go-crypto

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2018-06-08 22:36:24 -07:00

56 lines
1.3 KiB
Go

package commands
import (
"io"
cmdkit "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
)
// ErrorType signfies a category of errors
type ErrorType uint
// EncodingType defines a supported encoding
type EncodingType string
// Supported EncodingType constants.
const (
JSON = "json"
XML = "xml"
Protobuf = "protobuf"
Text = "text"
// TODO: support more encoding types
)
// Response is the result of a command request. Handlers write to the response,
// setting Error or Value. Response is returned to the client.
type Response interface {
Request() Request
// Set/Return the response Error
SetError(err error, code cmdkit.ErrorType)
Error() *cmdkit.Error
// Sets/Returns the response value
SetOutput(interface{})
Output() interface{}
// Sets/Returns the length of the output
SetLength(uint64)
Length() uint64
// underlying http connections need to be cleaned up, this is for that
Close() error
SetCloser(io.Closer)
// Marshal marshals out the response into a buffer. It uses the EncodingType
// on the Request to chose a Marshaler (Codec).
Marshal() (io.Reader, error)
// Gets a io.Reader that reads the marshalled output
Reader() (io.Reader, error)
// Gets Stdout and Stderr, for writing to console without using SetOutput
Stdout() io.Writer
Stderr() io.Writer
}