transport

package
Version: v0.0.0-...-5182803 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallError

func CallError(ctx context.Context, h *hooks.ServerHooks, err errors.Error) context.Context

Call .ServerHooks.Error if the hook is available

func CallRequestReceived

func CallRequestReceived(ctx context.Context, h *hooks.ServerHooks) (context.Context, error)

Call .ServerHooks.RequestReceived if the hook is available

func CallRequestRouted

func CallRequestRouted(ctx context.Context, h *hooks.ServerHooks) (context.Context, error)

Call .ServerHooks.RequestRouted if the hook is available

func CallResponsePrepared

func CallResponsePrepared(ctx context.Context, h *hooks.ServerHooks) context.Context

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 DecodeJSONRequest(ctx context.Context, req *http.Request, message proto.Message) error

func DecodePROTORequest

func DecodePROTORequest(ctx context.Context, req *http.Request, content proto.Message) error

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 EncodeJSONResponse(ctx context.Context, resp http.ResponseWriter, content proto.Message) error

func EncodePROTOResponse

func EncodePROTOResponse(ctx context.Context, resp http.ResponseWriter, content proto.Message) error

func ErrorFromIntermediary

func ErrorFromIntermediary(status int, msg string, bodyOrLocation string) errors.Error

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

func UrlBase(addr string) string

urlBase helps ensure that addr specifies a scheme. If it is unparsable as a URL, it returns addr unchanged.

func WithoutRedirects

func WithoutRedirects(in *http.Client) *http.Client

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

type DecodeRequestFunc func(ctx context.Context, resp *http.Request, content proto.Message) error

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

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

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

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL