Documentation
¶
Overview ¶
Package transport contains utility methods for API interfaces that speak to clients
Index ¶
- Variables
- func MethodNotAllowed() http.Handler
- func NotFound() http.Handler
- func RangeFromHeader(r *http.Request) (int64, int64, error)
- func RangeFromValues(start, end, size int64) string
- type Error
- type HTTP
- func (t HTTP) Decode(r *http.Request, out interface{}) error
- func (t HTTP) Error(ctx context.Context, w http.ResponseWriter, code int, msg string, ...)
- func (t HTTP) ErrorWithStack(ctx context.Context, w http.ResponseWriter, code int, msg string, ...)
- func (t HTTP) Respond(ctx context.Context, w http.ResponseWriter, body interface{}, code int)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoRangeHeader is the error used when attempting to parse a non-existent // range header. ErrNoRangeHeader = errors.New("no range header provided") // ErrInvalidRange is the error used when a range value cannot be parsed. ErrInvalidRange = errors.New("invalid range") )
Functions ¶
func MethodNotAllowed ¶
MethodNotAllowed returns an http.Handler implementation to be used when an HTTP call for an existing resource is using an invalid method.
func NotFound ¶
NotFound returns an http.Handler implementation to be used when a requested HTTP resource does not exist.
func RangeFromHeader ¶
RangeFromHeader determines the range of bytes to stream from the Range header.
func RangeFromValues ¶
RangeFromValues generates a Content-Range header using the provided values.
Types ¶
type HTTP ¶
type HTTP struct{}
The HTTP type contains utilities for interacting with HTTP requests.
func (HTTP) Decode ¶
Decode the contents of the request body into the given interface and perform validation on the struct.
func (HTTP) Error ¶
func (t HTTP) Error(ctx context.Context, w http.ResponseWriter, code int, msg string, args ...interface{})
Error returns a JSON-encoded error to the HTTP client.
func (HTTP) ErrorWithStack ¶
func (t HTTP) ErrorWithStack(ctx context.Context, w http.ResponseWriter, code int, msg string, args ...interface{})
ErrorWithStack returns a JSON-encoded error to the HTTP client that contains a stack trace. Should be used for debugging and handling panics.