Documentation ¶
Overview ¶
Package transport provides a JSON-RPC transport over standard IO streams.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type RequestSetReader ¶
func (*RequestSetReader) Read ¶
func (r *RequestSetReader) Read(ctx context.Context) (harpy.RequestSet, error)
Read reads the next RequestSet that is to be processed.
It returns ctx.Err() if ctx is canceled while waiting to read the next request set. If request set data is read but cannot be parsed a native JSON-RPC Error is returned. Any other error indicates an IO error.
type ResponseWriter ¶
ResponseWriter is an implementation of harpy.ResponseWriter that writes responses to an http.ResponseWriter.
func (*ResponseWriter) Close ¶
func (w *ResponseWriter) Close() error
Close is called to signal that there are no more responses to be sent.
If batched responses have been written, it writes the closing bracket of the array that encapsulates the responses.
func (*ResponseWriter) WriteBatched ¶
func (w *ResponseWriter) WriteBatched(res harpy.Response) error
WriteBatched writes a response to an individual request that was part of a batch.
If this is the first response of the batch, it immediately writes the HTTP response headers and the opening bracket of the array that encapsulates the batch of responses.
The HTTP status code is always 200 (OK), as even if res is an ErrorResponse, other responses in the batch may indicate a success.
func (*ResponseWriter) WriteError ¶
func (w *ResponseWriter) WriteError(res harpy.ErrorResponse) error
WriteError writes an error response that is a result of some problem with the request set as a whole.
It immediately writes the HTTP response headers followed by the HTTP body.
If the error code is pre-defined by the JSON-RPC specification the HTTP status code is set to the most appropriate equivalent, otherwise it is set to 500 (Internal Server Error).
func (*ResponseWriter) WriteUnbatched ¶
func (w *ResponseWriter) WriteUnbatched(res harpy.Response) error
WriteUnbatched writes a response to an individual request that was not part of a batch.
It immediately writes the HTTP response headers followed by the HTTP body.
If res is an ErrorResponse and its error code is pre-defined by the JSON-RPC specification the HTTP status code is set to the most appropriate equivalent.
Application-defined JSON-RPC errors always result in a HTTP 200 (OK), as they considered part of normal operation of the transport.