-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
kind/enhancementA net-new feature or improvement to an existing featureA net-new feature or improvement to an existing feature
Description
Currently, the "response emitter" has a single Emit function that magically determines the right thing to do. Unfortunately, this is really magical:
- We have a special "single" wrapper to inform HTTP that we're emitting a single value.
- If the user "emits" a reader, we copy it as a stream of bytes.
- If the user emits normal values (not
Single, we emit a stream of values).
This is getting better with the next iteration of the commands lib (this list used to include errors) but it could be improved.
Solutions:
- Have different command types. While the nicest from a type safety standpoint, this may not be the friendliest option.
- Apply a type-switch to the command's Run (and PostRun) functions. Personally, this is the one I'd vote for.
In the second case, we'd allow the following Run signatures:
// Writes a stream
type StreamFunc func(req *Request, resp io.Writer, env Environment) error
// Streams items
//
// We can keep this "magical" for now but eventually remove the magic and force users to use the other variants.
type EmitterFunc func(req *Request, resp ResponseEmitter, env Environment) error
// Sends a single item
type SingleFunc func(req *Request, env Environment) (interface{}, error)Thoughts? This should make sending HTTP responses simpler and will likely improve user experience.
Metadata
Metadata
Assignees
Labels
kind/enhancementA net-new feature or improvement to an existing featureA net-new feature or improvement to an existing feature