http

package
v0.0.0-...-1d97044 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BracketsRouterPatternBuilder uses brackets as route params delimiter
	BracketsRouterPatternBuilder = iota
	// ColonRouterPatternBuilder use a colon as route param delimiter
	ColonRouterPatternBuilder
	// DefaultMaxIdleConnsPerHost is the default value for the maxIdleConnsPerHost param
	DefaultMaxIdleConnsPerHost = 250
	// DefaultTimeout is the default value to use for the ServiceConfig.timeout param
	DefaultTimeout = 2 * time.Second

	// ConfigVersion is the current version of the error struct
	ConfigVersion = 1
)
View Source
const (
	DefaultReadTimeout           = 20 * time.Second
	DefaultWriteTimeout          = 20 * time.Second
	DefaultIdleTimeout           = 20 * time.Second
	DefaultReadHeaderTimeout     = 20 * time.Second
	DefaultResponseHeaderTimeout = 20 * time.Second
	DefaultExpectContinueTimeout = 20 * time.Second
	DefaultIdleConnTimeout       = 20 * time.Second
)
View Source
const (
	DialerTimeoutDefault       = 30 * time.Second
	DialerKeepAliveDefault     = 30 * time.Second
	DialerFallbackDelayDefault = 30 * time.Second
)
View Source
const (
	ConcurrentCallsDefault = 1
	DefaultCacheTTL        = 6 * time.Hour
)

Variables

This section is empty.

Functions

func NewAPIConfig

func NewAPIConfig(endpoints []*EndpointConfig, cacheTTL time.Duration, host []string, port uint64, version int, outputEncoding string, timeout time.Duration, APITime *APITimeoutConfig, CORS *CORSConfig, disableKeepAlives bool, disableCompression bool, maxIdleConns int, maxIdleConnsPerHost int,
	disableStrictREST bool, debug bool) (*httpModelConfigAVA.API, *errorAVA.Error)

func NewAPIConfigDefault

func NewAPIConfigDefault() (*httpModelConfigAVA.API, *errorAVA.Error)

func NewAPITimeoutConfig

func NewAPITimeoutConfig(readTimeout uint64, writeTimeout uint64, idleTimeout uint64, readHeaderTimeout uint64, idleConnTimeout uint64, responseHeaderTimeout uint64, expectContinueTimeout uint64, dialer *DialerConfig) (*httpModelConfigAVA.APITimeout, *errorAVA.Error)

func NewAPITimeoutConfigDefault

func NewAPITimeoutConfigDefault() (*httpModelConfigAVA.APITimeout, *errorAVA.Error)

func NewBackendConfig

func NewBackendConfig(group string, method string, host []string, hostSanitizationDisabled bool, url string, blacklist []string, whitelist []string, mapping map[string]string, encoding string, isCollection bool, target string, discoveryService string, urlKeys []string, concurrentCalls int,
	timeout time.Duration) (*httpModelConfigAVA.Backend, *errorAVA.Error)

func NewBackendConfigDefault

func NewBackendConfigDefault() (*httpModelConfigAVA.Backend, *errorAVA.Error)

func NewCORSConfig

func NewCORSConfig(allowOrigins []string, exposeHeaders []string, maxAge int, allowMethods []string, allowHeaders []string, allowCredentials bool, debug bool) (httpModelConfigAVA.CORS, *errorAVA.Error)

func NewCORSConfigDefault

func NewCORSConfigDefault() (httpModelConfigAVA.CORS, *errorAVA.Error)

func NewDialerConfig

func NewDialerConfig(dialerTimeout uint64, dialerFallbackDelay uint64, dialerKeepAlive uint64) (*http.Dialer, *errorAVA.Error)

func NewDialerConfigDefault

func NewDialerConfigDefault() (*http.Dialer, *errorAVA.Error)

func NewEndpointConfig

func NewEndpointConfig(URL string, method string, backend []*BackendConfig, discoveryService string, concurrentCalls int, timeout time.Duration, cacheTTL time.Duration, queryString []string, headersToPass []string, outputEncoding string) (*http.Endpoint, *errorAVA.Error)

func NewEndpointConfigDefault

func NewEndpointConfigDefault() (*http.Endpoint, *errorAVA.Error)

func NewTLSConfig

func NewTLSConfig(enable bool, publicKey string, privateKey string, minVersion string, maxVersion string, curvePreferences []string, preferServerCipherSuites bool, cipherSuites []string) (*http.TLS, *errorAVA.Error)

func NewTLSConfigDefault

func NewTLSConfigDefault() (*http.TLS, *errorAVA.Error)

Types

type APIConfig

type APIConfig struct {
	// set of endpoint definitions
	Endpoints []*EndpointConfig `mapstructure:"endpoints"`
	// default TTL for GET
	CacheTTL time.Duration `mapstructure:"cache_ttl"`
	// default set of hosts
	Host []string `mapstructure:"host"`
	//
	Port uint64 `mapstructure:"Port"`
	// version code of the configurationServiceI
	Version int `mapstructure:"version"`
	// OutputEncodingType defines the default error strategy to use for the endpoint responses
	OutputEncoding string `mapstructure:"output_encoding"`
	// defafult timeout
	Timeout time.Duration `mapstructure:"timeout"`

	// api time manager
	APITime *APITimeoutConfig `mapstructure:"time"`

	CORS *CORSConfig `mapstructure:"cors"`

	// disableKeepAlives, if true, prevents re-use of TCP connections between different HTTP requests.
	DisableKeepAlives bool `mapstructure:"disable_keep_alives"`
	// disableCompression, if true, prevents the Transport from
	// requesting compression with an "Accept-encoding: gzip"
	// request header when the Request contains no existing
	// Accept-encoding value. If the Transport requests gzip on
	// its own and gets a gzipped response, it's transparently
	// decoded in the Response.Body. However, if the user
	// explicitly requested gzip it is not automatically
	// uncompressed.
	DisableCompression bool `mapstructure:"disable_compression"`
	// maxIdleConns controls the maximum number of idle (keep-alive)
	// connections across all hosts. Zero means no limit.
	MaxIdleConns int `mapstructure:"max_idle_connections"`
	// maxIdleConnsPerHost, if non-zero, controls the maximum idle
	// (keep-alive) connections to keep per-host. If zero,
	// DefaultMaxIdleConnsPerHost is used.
	MaxIdleConnsPerHost int `mapstructure:"max_idle_connections_per_host"`

	// disableStrictREST flags if the REST enforcement is disabled
	DisableStrictREST bool `mapstructure:"disable_rest"`

	// run AVA in debug mode
	Debug bool `mapstructure:"debug"`
}

APIConfig defines the AVA stackMicroservices

func (*APIConfig) Parser

func (a *APIConfig) Parser() (*httpModelConfigAVA.API, *errorAVA.Error)

func (*APIConfig) ReadLocal

func (a *APIConfig) ReadLocal(fileName string) (*httpModelConfigAVA.API, *errorAVA.Error)

func (*APIConfig) Serializer

func (a *APIConfig) Serializer(t serializerAVA.SerializerType) ([]byte, *errorAVA.Error)

type APIConfigI

type APIConfigI interface {
	ReadLocal(fileName string) (*httpModelConfigAVA.API, *errorAVA.Error)
	Parser() (*httpModelConfigAVA.API, *errorAVA.Error)
	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

type APITimeoutConfig

type APITimeoutConfig struct {
	// ReadTimeout is the maximum duration for reading the entire request, including the body.
	//
	// Because ReadTimeout does not let Handlers make per-request decisions on each request body's acceptable deadline or upload rate, most users will prefer to use ReadHeaderTimeout. It is valid to use them both.
	ReadTimeout uint64 `mapstructure:"read_timeout,omitempty"`

	// WriteTimeout is the maximum duration before timing out writes of the response. It is reset whenever a new request's header is read. Like ReadTimeout, it does not let Handlers make decisions on a per-request basis.
	WriteTimeout uint64 `mapstructure:"write_timeout,omitempty"`

	// IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled. If IdleTimeout is zero, the value of ReadTimeout is used. If both are zero, ReadHeaderTimeout is used.
	IdleTimeout uint64 `mapstructure:"idle_timeout,omitempty"`

	// ReadHeaderTimeout is the amount of time allowed to read request headers. The connection's read deadline is reset after reading the headers and the Handler can decide what is considered too slow for the body.
	ReadHeaderTimeout uint64 `mapstructure:"read_header_timeout,omitempty"`

	// IdleConnTimeout is the maximum amount of time an idle (keep-alive) connection will remain idle before closing itself.
	// Zero means no limit.
	IdleConnTimeout uint64 `mapstructure:"idle_connection_timeout,omitempty"`

	// ResponseHeaderTimeout, if non-zero, specifies the amount of time to wait for a server's response headers after fully writing the request (including its body, if any). This time does not include the time to read the response body.
	ResponseHeaderTimeout uint64 `mapstructure:"response_header_timeout,omitempty"`

	// ExpectContinueTimeout, if non-zero, specifies the amount of time to wait for a server's first response headers after fully writing the request headers if the request has an "Expect: 100-continue" header. Zero means no timeout and causes the body to be sent immediately, without waiting for the server to approve.
	// This time does not include the time to send the request header.
	ExpectContinueTimeout uint64 `mapstructure:"expect_continue_timeout,omitempty"`

	//  timeout time manager
	Dialer *DialerConfig `mapstructure:"dialer,omitempty"`
}

func (*APITimeoutConfig) Parser

func (*APITimeoutConfig) ReadLocal

func (a *APITimeoutConfig) ReadLocal(fileName string) (*httpModelConfigAVA.APITimeout, *errorAVA.Error)

func (*APITimeoutConfig) Serializer

type APITimeoutConfigI

type APITimeoutConfigI interface {
	ReadLocal(fileName string) (*httpModelConfigAVA.APITimeout, *errorAVA.Error)
	Parser() (*httpModelConfigAVA.APITimeout, *errorAVA.Error)
	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

type BackendConfig

type BackendConfig struct {
	// the name of the group the response should be moved to. If empty, the response is not changed
	Group string `mapstructure:"group"`
	// HTTP Method of the request to send to the backend
	Method string `mapstructure:"Method"`
	// Set of hosts of the api
	Host []string `mapstructure:"host"`
	// False if the hostname should be sanitized
	HostSanitizationDisabled bool `mapstructure:"disable_host_sanitize"`
	// url pattern to use to locate the resource to be consumed
	Url string `mapstructure:"url_pattern"`
	// set of response fields to remove. If empty, the filter id not used
	Blacklist []string `mapstructure:"blacklist"`
	// set of response fields to allow. If empty, the filter id not used
	Whitelist []string `mapstructure:"whitelist"`
	// map of response fields to be renamed and their new names
	Mapping map[string]string `mapstructure:"mapping"`
	// the error format
	Encoding string `mapstructure:"error"`
	// the response to process is a collection
	IsCollection bool `mapstructure:"is_collection"`
	// name of the field to extract to the root. If empty, the formater will do nothing
	Target string `mapstructure:"target"`
	// name of the stackMicroservices discoveryService driver to use
	DiscoveryService string `mapstructure:"discovery_service_name"`

	// list of keys to be replaced in the url
	UrlKeys []string `mapstructure:"urlKeys"`
	// number of concurrent calls this endpoint must send to the api
	ConcurrentCalls int `mapstructure:"concurrentCalls"`
	// timeout of this backend
	Timeout time.Duration `mapstructure:"timeout"`
}

BackendConfig defines how AVA should connect to the BackendConfig stackMicroservices (the api resource to consume) and how it should process the received response

func (*BackendConfig) Parser

func (b *BackendConfig) Parser(disableStrictREST bool, urlPattern string) (*httpModelConfigAVA.Backend, *errorAVA.Error)

func (*BackendConfig) ReadLocal

func (b *BackendConfig) ReadLocal(fileName string) (*httpModelConfigAVA.Backend, *errorAVA.Error)

func (*BackendConfig) Serializer

type BackendConfigI

type BackendConfigI interface {
	ReadLocal(fileName string) (*httpModelConfigAVA.Backend, *errorAVA.Error)
	Parser(disableStrictREST bool, urlPattern string) (*httpModelConfigAVA.Backend, *errorAVA.Error)
	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

type CORSConfig

type CORSConfig struct {
	// contains filtered or unexported fields
}

func (*CORSConfig) Parser

func (cors *CORSConfig) Parser() (*httpModelConfigAVA.CORS, *errorAVA.Error)

func (*CORSConfig) ReadLocal

func (cors *CORSConfig) ReadLocal(fileName string) (*httpModelConfigAVA.CORS, *errorAVA.Error)

func (*CORSConfig) Serializer

func (cors *CORSConfig) Serializer(t serializerAVA.SerializerType) ([]byte, *errorAVA.Error)

type CORSConfigI

type CORSConfigI interface {
	ReadLocal(fileName string) (*httpModelConfigAVA.CORS, *errorAVA.Error)
	Parser() (*httpModelConfigAVA.CORS, *errorAVA.Error)
	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

type DialerConfig

type DialerConfig struct {
	// DialerTimeout is the maximum amount of time a dial will wait for a connect to complete. If Deadline is also set, it may fail earlier.
	// The default is no timeout.
	//
	// When using TCP and dialing a host name with multiple IP addresses, the timeout may be divided between them.
	//
	// With or without a timeout, the operating system may impose its own earlier timeout. For instance, TCP timeouts are often around 3 minutes.
	DialerTimeout uint64 `mapstructure:"dialer_timeout,omitempty"`
	// FallbackDelay specifies the length of time to wait before spawning a fallback connection, when DualStack is enabled.
	// If zero, a default delay of 300ms is used.
	DialerFallbackDelay uint64 `mapstructure:"dialer_fallback_delay,omitempty"`
	// KeepAlive specifies the keep-alive period for an active network connection.
	// If zero, keep-alives are not enabled. Network protocols that do not support keep-alives ignore this field.
	DialerKeepAlive uint64 `mapstructure:"dialer_keep_alive,omitempty"`
}

func (*DialerConfig) Parser

func (a *DialerConfig) Parser() (*http.Dialer, *errorAVA.Error)

func (*DialerConfig) ReadLocal

func (a *DialerConfig) ReadLocal(fileName string) (*http.Dialer, *errorAVA.Error)

func (*DialerConfig) Serializer

type DialerConfigI

type DialerConfigI interface {
	ReadLocal(fileName string) (*http.Dialer, *errorAVA.Error)
	Parser() (*http.Dialer, *errorAVA.Error)
	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

type EndpointConfig

type EndpointConfig struct {
	// url pattern to be registered and exposed to the world
	URL string `mapstructure:"url"`
	// HTTP Method of the endpoint (GET, POST, PUT, etc)
	Method string `mapstructure:"Method"`
	// set of definitions of the backends to be linked to this endpoint
	Backend []*BackendConfig `mapstructure:"backend"`
	//
	DiscoveryService string `mapstructure:"discovery_service_name"`
	// number of concurrent calls this endpoint must send to the backends
	ConcurrentCalls int `mapstructure:"concurrent_calls"`
	// timeout of this endpoint
	Timeout time.Duration `mapstructure:"timeout"`
	// duration of the cache header
	CacheTTL time.Duration `mapstructure:"cache_ttl"`
	// list of query string params to be extracted from the URI
	QueryString []string `mapstructure:"querystring_params"`
	// headersToPass defines the list of headers to pass to the backends
	HeadersToPass []string `mapstructure:"headers_to_pass"`
	// OutputEncodingType defines the error strategy to use for the endpoint responses
	OutputEncoding string `mapstructure:"output_encoding"`
}

func (*EndpointConfig) Parser

func (e *EndpointConfig) Parser(api *APIConfig) (*http.Endpoint, *errorAVA.Error)

func (*EndpointConfig) ReadLocal

func (e *EndpointConfig) ReadLocal(fileName string) (*http.Endpoint, *errorAVA.Error)

func (*EndpointConfig) Serializer

type EndpointConfigI

type EndpointConfigI interface {
	ReadLocal(fileName string) (*http.Endpoint, *errorAVA.Error)
	Parser(api *APIConfig) (*http.Endpoint, *errorAVA.Error)
	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

type TLSConfig

type TLSConfig struct {
	Enable                   bool     `mapstructure:"enable,omitempty"`
	PublicKey                string   `mapstructure:"public_key"`
	PrivateKey               string   `mapstructure:"private_key"`
	MinVersion               string   `mapstructure:"min_version,omitempty"`
	MaxVersion               string   `mapstructure:"max_version,omitempty"`
	CurvePreferences         []string `mapstructure:"curve_preferences"`
	PreferServerCipherSuites bool     `mapstructure:"prefer_server_cipher_suites"`
	CipherSuites             []string `mapstructure:"cipher_suites"`
}

TLSConfig defines the configuration service params for enabling tls (HTTPS & HTTP/2) at the router layer

func (*TLSConfig) Parser

func (tls *TLSConfig) Parser() (*http.TLS, *errorAVA.Error)

func (*TLSConfig) ReadLocal

func (tls *TLSConfig) ReadLocal(fileName string) (*http.TLS, *errorAVA.Error)

func (*TLSConfig) Serializer

func (tls *TLSConfig) Serializer(t serializerAVA.SerializerType) ([]byte, *errorAVA.Error)

type TLSConfigI

type TLSConfigI interface {
	ReadLocal(fileName string) (*http.TLS, *errorAVA.Error)
	Parser() (*http.TLS, *errorAVA.Error)
	Serializer(serializerAVA.SerializerType) ([]byte, *errorAVA.Error)
}

Jump to

Keyboard shortcuts

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