Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // If client is nil, http.DefaultClient will be used. *http.Client // Method must be provided. Method string // URL must be provided. URL *url.URL // A background context must be provided. context.Context // EncodeRequestFunc must be provided. The HTTP request passed to the // EncodeRequestFunc will have a nil body. EncodeRequestFunc // DecodeResponseFunc must be provided. DecodeResponseFunc // Before functions are executed on the outgoing request after it is // created, but before it's sent to the HTTP client. Clients have no After // ResponseFuncs, as they don't work with ResponseWriters. Before []RequestFunc }
Client wraps a URL and provides a method that implements endpoint.Endpoint.
type DecodeRequestFunc ¶
DecodeRequestFunc extracts a user-domain request object from an HTTP request object. It's designed to be used in HTTP servers, for server-side endpoints. One straightforward DecodeRequestFunc could be something that JSON decodes from the request body to the concrete response type.
type DecodeResponseFunc ¶
DecodeResponseFunc extracts a user-domain response object from an HTTP response object. It's designed to be used in HTTP clients, for client-side endpoints. One straightforward DecodeResponseFunc could be something that JSON decodes from the response body to the concrete response type.
type EncodeRequestFunc ¶
EncodeRequestFunc encodes the passed request object into the HTTP request object. It's designed to be used in HTTP clients, for client-side endpoints. One straightforward EncodeRequestFunc could something that JSON encodes the object directly to the request body.
type EncodeResponseFunc ¶
type EncodeResponseFunc func(http.ResponseWriter, interface{}) error
EncodeResponseFunc encodes the passed response object to the HTTP response writer. It's designed to be used in HTTP servers, for server-side endpoints. One straightforward EncodeResponseFunc could be something that JSON encodes the object directly to the response body.
type RequestFunc ¶
RequestFunc may take information from an HTTP request and put it into a request context. In Servers, BeforeFuncs are executed prior to invoking the endpoint. In Clients, BeforeFuncs are executed after creating the request but prior to invoking the HTTP client.
func SetRequestHeader ¶
func SetRequestHeader(key, val string) RequestFunc
SetRequestHeader returns a RequestFunc that sets the specified header.
type ResponseFunc ¶
type ResponseFunc func(context.Context, http.ResponseWriter)
ResponseFunc may take information from a request context and use it to manipulate a ResponseWriter. ResponseFuncs are only executed in servers, after invoking the endpoint but prior to writing a response.
func SetContentType ¶
func SetContentType(contentType string) ResponseFunc
SetContentType returns a ResponseFunc that sets the Content-Type header to the provided value.
func SetResponseHeader ¶
func SetResponseHeader(key, val string) ResponseFunc
SetResponseHeader returns a ResponseFunc that sets the specified header.
type Server ¶
type Server struct { // A background context must be provided. context.Context // The endpoint that will be invoked. endpoint.Endpoint // DecodeRequestFunc must be provided. DecodeRequestFunc // EncodeResponseFunc must be provided. EncodeResponseFunc // Before functions are executed on the HTTP request object before the // request is decoded. Before []RequestFunc // After functions are executed on the HTTP response writer after the // endpoint is invoked, but before anything is written to the client. After []ResponseFunc // ErrorEncoder is used to encode errors to the http.ResponseWriter // whenever they're encountered in the processing of a request. Clients // can use this to provide custom error formatting and response codes. If // ErrorEncoder is nil, the error will be written as plain text with // an appropriate, if generic, status code. ErrorEncoder func(w http.ResponseWriter, err error) }
Server wraps an endpoint and implements http.Handler.