Created
December 18, 2016 16:45
-
-
Save keks/450b31fd2032ffc65a01fc911e70b77d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ResponseEmitter interface { | |
// closes http conn or channel | |
io.Closer | |
// Set/Return the response Error | |
SetError(err error, code ErrorType) | |
// Gets Stdout and Stderr, for writing to console without using SetOutput | |
Stdout() io.Writer | |
Stderr() io.Writer | |
// send value | |
// if value is io.Reader there needs to be a marshaller that copies that to the connection | |
Emit(value interface{}) error | |
} | |
type HTTPResponseEmitter interface { | |
ReponseEmitter | |
SetLength(i uint64) error | |
Flush() | |
} | |
// implements HTTPResponseEmitter | |
type httpResponseEmitter struct { | |
// ... | |
} | |
type writerResponseEmitter struct { | |
// ... | |
} | |
// implements ResponseEmitter | |
type chanResponseEmitter struct { | |
// ... | |
} | |
/* NewResponse: | |
Currently cmds.NewResponse only takes a request as parameter. | |
From now on it also takes the destination. This can be an http.ResponseWriter, | |
an io.Writer or a channel: | |
func NewHTTPResponseEmitter(req Request, http.ResponseWriter) ResponseEmitter | |
func NewWriterResponseEmitter(req Request, io.Writer) ResponseEmitter | |
func NewChanResponseEmitter(req Request, chan<- interface{}) ResponseEmitter | |
Note that different concrete implementations will be used. If transport-specific | |
features are needed, you can type-assert to an interface that provides that. | |
At the moment the only transport with special features is HTTP. | |
There are not many uses of NewResponse so this is not really a problem: | |
github.com/ipfs/go-ipfs/commands/response.go:245:6: github.com/ipfs/go-ipfs/commands.NewResponse is called from these 3 sites: | |
github.com/ipfs/go-ipfs/commands/command.go:90:20: static function call from (*github.com/ipfs/go-ipfs/commands.Command).Call | |
github.com/ipfs/go-ipfs/commands/response_test.go:21:20: static function call from github.com/ipfs/go-ipfs/commands.TestMarshalling | |
github.com/ipfs/go-ipfs/commands/http/client.go:157:25: static function call from github.com/ipfs/go-ipfs/commands/http.getResponse | |
*/ | |
/* cmd.Call: | |
Currently the first thing it does is to call NewResponse. We pull that out: | |
`cmd.Call(req, respwr)` | |
cmd.Call is only called in a few places so its not a lot of work: | |
github.com/ipfs/go-ipfs/commands/command.go:89:19: (*github.com/ipfs/go-ipfs/commands.Command).Call is called from these 10 sites: | |
github.com/ipfs/go-ipfs/cmd/ipfs/main.go:349:18: static method call from github.com/ipfs/go-ipfs/cmd/ipfs.callCommand | |
github.com/ipfs/go-ipfs/commands/http/handler.go:186:20: static method call from (github.com/ipfs/go-ipfs/commands/http.internalHandler).ServeHTTP | |
github.com/ipfs/go-ipfs/commands/command_test.go:22:17: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
github.com/ipfs/go-ipfs/commands/command_test.go:29:16: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
github.com/ipfs/go-ipfs/commands/command_test.go:37:16: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
github.com/ipfs/go-ipfs/commands/command_test.go:45:16: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
github.com/ipfs/go-ipfs/commands/command_test.go:52:16: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
github.com/ipfs/go-ipfs/commands/command_test.go:59:16: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
github.com/ipfs/go-ipfs/commands/command_test.go:66:16: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
github.com/ipfs/go-ipfs/commands/command_test.go:73:16: static method call from github.com/ipfs/go-ipfs/commands.TestOptionValidation | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment