Documentation ¶
Index ¶
Constants ¶
const ( // DomainNewRequest is an error during request generation. DomainNewRequest = "NewRequest" // DomainEncode is an error during request or response encoding. DomainEncode = "Encode" // DomainDo is an error during the execution phase of the request. DomainDo = "Do" // DomainDecode is an error during request or response decoding. DomainDecode = "Decode" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a URL and provides a method that implements endpoint.Endpoint.
func NewClient ¶
func NewClient( method string, tgt *url.URL, enc EncodeRequestFunc, dec DecodeResponseFunc, options ...ClientOption, ) *Client
NewClient constructs a usable Client for a single remote endpoint.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption sets an optional parameter for clients.
func SetBufferedStream ¶
func SetBufferedStream(buffered bool) ClientOption
SetBufferedStream sets whether the Response.Body is left open, allowing it to be read from later. Useful for transporting a file as a buffered stream.
func SetClient ¶
func SetClient(client *http.Client) ClientOption
SetClient sets the underlying HTTP client used for requests. By default, http.DefaultClient is used.
func SetClientBefore ¶
func SetClientBefore(before ...RequestFunc) ClientOption
SetClientBefore sets the RequestFuncs that are applied to the outgoing HTTP request before it's invoked.
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(context.Context, 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 Error ¶
type Error struct { // Domain is the phase in which the error was generated. Domain string // Err is the concrete error. Err error }
Error is an error that occurred at some phase within the transport.
type ErrorEncoder ¶
type ErrorEncoder func(ctx context.Context, err error, w http.ResponseWriter)
ErrorEncoder is responsible for encoding an error to the ResponseWriter.
In the server implementation, only kit/transport/http.Error values are ever passed to this function, so you might be tempted to have this function take one of those directly. But, users are encouraged to use custom ErrorEncoders to encode all HTTP errors to their clients, and so may want to pass and check for their own error types. See the example shipping/handling service.
type RequestFunc ¶
RequestFunc may take information from an HTTP request and put it into a request context. In Servers, RequestFuncs are executed prior to invoking the endpoint. In Clients, RequestFuncs 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 {
// contains filtered or unexported fields
}
Server wraps an endpoint and implements http.Handler.
func NewServer ¶
func NewServer( ctx context.Context, e endpoint.Endpoint, dec DecodeRequestFunc, enc EncodeResponseFunc, options ...ServerOption, ) *Server
NewServer constructs a new server, which implements http.Server and wraps the provided endpoint.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption sets an optional parameter for servers.
func ServerAfter ¶
func ServerAfter(after ...ResponseFunc) ServerOption
ServerAfter functions are executed on the HTTP response writer after the endpoint is invoked, but before anything is written to the client.
func ServerBefore ¶
func ServerBefore(before ...RequestFunc) ServerOption
ServerBefore functions are executed on the HTTP request object before the request is decoded.
func ServerErrorEncoder ¶
func ServerErrorEncoder(ee ErrorEncoder) ServerOption
ServerErrorEncoder 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. By default, errors will be written as plain text with an appropriate, if generic, status code.
func ServerErrorLogger ¶
func ServerErrorLogger(logger log.Logger) ServerOption
ServerErrorLogger is used to log non-terminal errors. By default, no errors are logged.