Documentation ¶
Index ¶
- Constants
- func EnforceRelativeLocation(resp *http.Response) error
- func Help(ctx context.Context, components ...NewComponent) (string, error)
- func New(ctx context.Context, specification []byte, components ...NewComponent) (*runhttp.Runtime, error)
- func NewRuntime(ctx context.Context, s settings.Source, h http.Handler) (*runhttp.Runtime, error)
- func NewTransport(ctx context.Context, specification []byte, components ...NewComponent) (http.RoundTripper, error)
- func PathParamsFromContext(ctx context.Context) map[string]string
- func PathParamsToContext(ctx context.Context, params map[string]string) context.Context
- func RouteFromContext(ctx context.Context) *openapi3filter.Route
- func RouteToContext(ctx context.Context, route *openapi3filter.Route) context.Context
- func RuntimeSourceFromExtension(s []byte) (settings.Source, error)
- func SourceFromExtension(s []byte) (settings.Source, error)
- type BackendRegistry
- type ClientFactory
- type ClientRegistry
- type ClientTransport
- type EnvProcessor
- type HTTPError
- type MultiResponseModifier
- type NewComponent
- type StaticBackendRegistry
- type StaticClientRegistry
Constants ¶
const ( // DefaultBackend is the value given when a particular route is not part // of a known, named backend. DefaultBackend = "default" )
const ( // ExtensionKey is used to identify OpenAPI extension blocks // that are relevant to this project. ExtensionKey = "x-transportd" )
const ( // RuntimeExtensionKey is used to identify the runtime configuration // extension block at the top level of an OpenAPI specification. RuntimeExtensionKey = "x-runtime" )
Variables ¶
This section is empty.
Functions ¶
func EnforceRelativeLocation ¶ added in v0.4.0
EnforceRelativeLocation prevents redirection from the backend as the result of 3xx codes from improperly redirecting clients around the proxy. This is related to https://github.com/golang/go/issues/14237.
func Help ¶
func Help(ctx context.Context, components ...NewComponent) (string, error)
Help outputs a formatted string to help with discovering available settings and options.
func New ¶
func New(ctx context.Context, specification []byte, components ...NewComponent) (*runhttp.Runtime, error)
New generates a configured HTTP runtime. To use as a library, call the NewTransport method instead.
func NewRuntime ¶
NewRuntime generates a runhttp.Runtime instance that will host the given handler. This method is used to handle the top-level x-runtime block.
func NewTransport ¶
func NewTransport(ctx context.Context, specification []byte, components ...NewComponent) (http.RoundTripper, error)
NewTransport constructs a smart HTTP client from the given specification and set of plugins. For running a service, use the New method instead.
func PathParamsFromContext ¶
PathParamsFromContext fetches the matching URL params.
func PathParamsToContext ¶
PathParamsToContext inserts the matching URL params.
func RouteFromContext ¶
func RouteFromContext(ctx context.Context) *openapi3filter.Route
RouteFromContext fetches the active OpenAPI route.
func RouteToContext ¶
RouteToContext inserts the active OpenAPI route.
func RuntimeSourceFromExtension ¶
RuntimeSourceFromExtension is a one-off change from the SourceFromExtension method that handles the runhttp configuration block. This is needed because the runhttp component has a predefined root of "runtime" that we need to adapt the source to match.
Types ¶
type BackendRegistry ¶
type BackendRegistry interface { Load(ctx context.Context, backend string) http.RoundTripper Store(ctx context.Context, backend string, rt http.RoundTripper) }
BackendRegistry manages a set of base http.RoundTripper implementations that are composed with other tools in order to create clients.
func NewBaseTransports ¶
NewBaseTransports generates a mapping of backend names to http.RoundTripper instances. This method is used to handle the top-level x-transportd block and configure a set of base http.RoundTripper instances with some core connection pooling settings applied.
type ClientFactory ¶
type ClientFactory struct { Bases BackendRegistry Components []NewComponent }
ClientFactory exposes a Client constructor method that is bound to a given sregistry and set of plugin components.
type ClientRegistry ¶
type ClientRegistry interface { Load(ctx context.Context, path string, method string) http.RoundTripper Store(ctx context.Context, path string, method string, rt http.RoundTripper) }
ClientRegistry manages a set of configured http.RoundTripper implementations that will be used to make requests.
type ClientTransport ¶
type ClientTransport struct { Registry ClientRegistry Router *openapi3filter.Router }
ClientTransport maps incoming requests to a configured client.
type EnvProcessor ¶
type EnvProcessor struct {
// contains filtered or unexported fields
}
EnvProcessor transforms documents by interpolating environment variables.
func NewEnvProcessor ¶
func NewEnvProcessor() *EnvProcessor
NewEnvProcessor prepares the EnvProcessor and returns it.
type HTTPError ¶
type HTTPError struct { // Code is the HTTP status code. Code int `json:"code"` // Status is the HTTP status string. Status string `json:"status"` // Reason is the debug data. Reason string `json:"reason"` }
HTTPError is the canonical shape for all internally generated HTTP error responses. All components should emit this shape, with an application/json content type, any time the component would return an internally crafted response. External developers are encouraged to embed this code in your project rather than importing it to avoid an unnecessary reference.
The purpose of standardizing on this structure is to enable users of this project to add a default response schema for output validation. For the same reasons, we recommend that projects behind this proxy also use this structure for errors.
type MultiResponseModifier ¶ added in v0.4.0
MultiResponseModifier enables composition of ModifyResponse functions.
func (MultiResponseModifier) ModifyResponse ¶ added in v0.4.0
func (mrs MultiResponseModifier) ModifyResponse(resp *http.Response) error
ModifyResponse satisfies the signature of the same name in the ReverseProxy.
type NewComponent ¶
type NewComponent func(ctx context.Context, backend string, path string, method string) (interface{}, error)
NewComponent is the signature all component plugins must implement. It is a constructor function that will be given the current backend and path for which the system is generating the component. The resulting value must implement the Component interface from the 'settings' project.
type StaticBackendRegistry ¶
type StaticBackendRegistry struct {
Transports map[string]http.RoundTripper
}
StaticBackendRegistry is an implementation of BackendRegistry that operates on a static mapping. This implementation exists, largely, in order to control for case insensitivity in the map.
func NewStaticBackendRegistry ¶
func NewStaticBackendRegistry() *StaticBackendRegistry
NewStaticBackendRegistry initializes a StaticBackendRegistry.
func (*StaticBackendRegistry) Load ¶
func (r *StaticBackendRegistry) Load(_ context.Context, backend string) http.RoundTripper
Load the transport base for a backend. Result may be nil if unset.
func (*StaticBackendRegistry) Store ¶
func (r *StaticBackendRegistry) Store(_ context.Context, backend string, rt http.RoundTripper)
Store a base transport for a backend.
type StaticClientRegistry ¶
type StaticClientRegistry struct {
Transports map[string]map[string]http.RoundTripper
}
StaticClientRegistry is an implementation of ClientRegisty that operates on a static mapping. This exists, largely, to protect consumers from case insensitivity issues.
func NewStaticClientRegistry ¶
func NewStaticClientRegistry() *StaticClientRegistry
NewStaticClientRegistry intializes the StaticClientRegistry.
func (*StaticClientRegistry) Load ¶
func (r *StaticClientRegistry) Load(_ context.Context, path string, method string) http.RoundTripper
Load a client for the path and method. The result may be nil if a client was never stored.
func (*StaticClientRegistry) Store ¶
func (r *StaticClientRegistry) Store(_ context.Context, path string, method string, rt http.RoundTripper)
Store a client for the path and method.