http

package
v0.0.0-...-c504454 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadRequestError

type BadRequestError struct {
	Err error
}

BadRequestError is an error in decoding the request.

func (BadRequestError) Error

func (err BadRequestError) Error() string

Error implements the error interface.

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.

func (Client) Endpoint

func (c Client) Endpoint() endpoint.Endpoint

Endpoint returns a usable endpoint that will invoke the RPC specified by the client.

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

type DecodeRequestFunc func(*http.Request) (request interface{}, err error)

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

type DecodeResponseFunc func(*http.Response) (response interface{}, err error)

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

type EncodeRequestFunc func(*http.Request, interface{}) error

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

type RequestFunc func(context.Context, *http.Request) context.Context

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 {
	// 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.

func (Server) ServeHTTP

func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

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(f func(w http.ResponseWriter, err error)) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL