Documentation ¶
Index ¶
- func CallError(ctx context.Context, h *hooks.ServerHooks, err errors.Error) context.Context
- func CallRequestReceived(ctx context.Context, h *hooks.ServerHooks) (context.Context, error)
- func CallRequestRouted(ctx context.Context, h *hooks.ServerHooks) (context.Context, error)
- func CallResponsePrepared(ctx context.Context, h *hooks.ServerHooks) context.Context
- func CallResponseSent(ctx context.Context, h *hooks.ServerHooks)
- func Closebody(body io.Closer, errorFunc LogErrorFunc)
- func DecodeJSONRequest(ctx context.Context, req *http.Request, message proto.Message) error
- func DecodePROTORequest(ctx context.Context, req *http.Request, content proto.Message) error
- func DoJSONRequest(ctx context.Context, client HTTPClient, url string, in, out proto.Message) (err error)
- func DoProtobufferRequest(ctx context.Context, client HTTPClient, url string, in, out proto.Message) (err error)
- func EncodeJSONResponse(ctx context.Context, resp http.ResponseWriter, content proto.Message) error
- func EncodePROTOResponse(ctx context.Context, resp http.ResponseWriter, content proto.Message) error
- func ErrorFromIntermediary(status int, msg string, bodyOrLocation string) errors.Error
- func UrlBase(addr string) string
- func WithoutRedirects(in *http.Client) *http.Client
- func WriteError(resp http.ResponseWriter, err error)
- func WriteErrorAndTriggerHooks(ctx context.Context, resp http.ResponseWriter, err error, ...)
- type DecodeRequestFunc
- type EncodeResponseFunc
- type HTTPClient
- type LogErrorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallRequestReceived ¶
Call .ServerHooks.RequestReceived if the hook is available
func CallRequestRouted ¶
Call .ServerHooks.RequestRouted if the hook is available
func CallResponsePrepared ¶
Call .ServerHooks.ResponsePrepared if the hook is available
func CallResponseSent ¶
func CallResponseSent(ctx context.Context, h *hooks.ServerHooks)
Call .ServerHooks.ResponseSent if the hook is available
func Closebody ¶
func Closebody(body io.Closer, errorFunc LogErrorFunc)
closebody closes a response or request body and just logs any error encountered while closing, since errors are considered very unusual.
func DecodeJSONRequest ¶
func DecodePROTORequest ¶
func DoJSONRequest ¶
func DoJSONRequest(ctx context.Context, client HTTPClient, url string, in, out proto.Message) (err error)
doJSONRequest is common code to make a request to the remote service.
func DoProtobufferRequest ¶
func DoProtobufferRequest(ctx context.Context, client HTTPClient, url string, in, out proto.Message) (err error)
doProtobufRequest is common code to make a request to the remote service.
func EncodeJSONResponse ¶
func EncodePROTOResponse ¶
func ErrorFromIntermediary ¶
ErrorFromIntermediary maps HTTP errors from sources to errors. The mapping is similar to gRPC: https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. Returned Errors have some additional metadata for inspection.
func UrlBase ¶
urlBase helps ensure that addr specifies a scheme. If it is unparsable as a URL, it returns addr unchanged.
func WithoutRedirects ¶
The standard library will, by default, redirect requests (including POSTs) if it gets a 302 or 303 response, and also 301s in go1.8. It redirects by making a second request, changing the method to GET and removing the body. This produces very confusing error messages, so instead we set a redirect policy that always errors. This stops Go from executing the redirect.
We have to be a little careful in case the user-provided http.Client has its own CheckRedirect policy - if so, we'll run through that policy first.
Because this requires modifying the http.Client, we make a new copy of the client and return it.
func WriteError ¶
func WriteError(resp http.ResponseWriter, err error)
WriteError writes an HTTP response with a valid error format. If err is not a .Error, it will get wrapped with .InternalErrorWith(err)
func WriteErrorAndTriggerHooks ¶
func WriteErrorAndTriggerHooks(ctx context.Context, resp http.ResponseWriter, err error, hooks *hooks.ServerHooks)
writeError writes errors in the response and triggers hooks.
Types ¶
type DecodeRequestFunc ¶
DecodeRequestFunc extracts a user-domain request object from an HTTP request object.
type EncodeResponseFunc ¶
type EncodeResponseFunc func(ctx context.Context, resp http.ResponseWriter, content proto.Message) error
EncodeResponseFunc encodes the passed response object to the proto encoder.
type HTTPClient ¶
HTTPClient is the interface used by generated clients to send HTTP requests. It is fulfilled by *(net/http).Client, which is sufficient for most users. Users can provide their own implementation for special retry policies.
HTTPClient implementations should not follow redirects. Redirects are automatically disabled if *(net/http).Client is passed to client constructors. See the withoutRedirects function in this file for more details.
type LogErrorFunc ¶
type LogErrorFunc func(format string, args ...interface{})
LogErrorFunc logs critical errors