httpconfig

package
v0.0.0-...-80ce5d5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientFromConfig

func NewClientFromConfig(
	config *HTTPClientConfig,
	options ...gohttpc.ClientOption,
) (*gohttpc.Client, error)

NewClientFromConfig creates a HTTP client wrapper with configuration.

func NewClientOptionsFromConfig

func NewClientOptionsFromConfig(
	config *HTTPClientConfig,
	options ...gohttpc.ClientOption,
) (*gohttpc.ClientOptions, error)

NewClientOptionsFromConfig creates a client options from configuration.

func NewHTTPClientFromConfig

func NewHTTPClientFromConfig(
	config *HTTPClientConfig,
	options *gohttpc.ClientOptions,
) (*http.Client, error)

NewHTTPClientFromConfig creates a HTTP client with configuration.

Types

type HTTPClientConfig

type HTTPClientConfig struct {
	// Default maximum timeout in seconds that is applied for all requests.
	Timeout int `json:"timeout,omitempty" jsonschema:"minimum=0" yaml:"timeout"`
	// Transport stores the http.Transport configuration for the http client.
	Transport *gohttpc.HTTPTransportConfig `json:"transport,omitempty" yaml:"transport,omitempty"`
	// The transport layer security (LTS) configuration for the mutualTLS authentication.
	TLS *TLSConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
	// Retry policy of client requests.
	Retry *HTTPRetryConfig `json:"retry,omitempty" yaml:"retry,omitempty"`
	// Authentication configuration.
	Authentication *authc.HTTPClientAuthConfig `json:"authentication,omitempty" yaml:"authentication,omitempty"`
}

HTTPClientConfig contains configurations to create client.

func (HTTPClientConfig) Equal

func (j HTTPClientConfig) Equal(target HTTPClientConfig) bool

Equal checks if the target value is equal.

func (*HTTPClientConfig) IsZero

func (c *HTTPClientConfig) IsZero() bool

IsZero if the current instance is empty.

type HTTPRetryConfig

type HTTPRetryConfig struct {
	// Maximum number of retry attempts.
	MaxAttempts int `json:"maxAttempts,omitempty" jsonschema:"minimum=0" mapstructure:"maxAttempts" yaml:"maxAttempts"`
	// The initial wait time in milliseconds before a retry is attempted.
	// Must be >0. Defaults to 1 second.
	Delay *int64 `json:"delay,omitempty" jsonschema:"minimum=1,default=1" mapstructure:"delay" yaml:"delay,omitempty"`
	// The max delay in milliseconds of the exponentially backing off.
	// If the max delay is smaller or equal the base delay. The delay is constant.
	MaxDelay *int64 `json:"maxDelay,omitempty" jsonschema:"minimum=1" mapstructure:"maxDelay" yaml:"maxDelay,omitempty"`
	// HTTPStatus retries if the remote service returns one of these http status
	HTTPStatus []int `json:"httpStatus,omitempty" mapstructure:"httpStatus" yaml:"httpStatus,omitempty"`
	// How much should the reconnection time grow on subsequent attempts.
	// Must be >=1; 1 = constant interval. Defaults to 1.5.
	Multiplier *float64 `json:"multiplier,omitempty" jsonschema:"minimum=1" mapstructure:"multiplier" yaml:"multiplier,omitempty"`
	// For each retry delay, a random portion of the jitter will be added or subtracted to the delay.
	// For example: a jitter of 100 milliseconds will randomly add between -100 and 100 milliseconds to each retry delay.
	// Replaces any previously configured jitter factor.
	Jitter *int64 `json:"jitter,omitempty" mapstructure:"jitter" yaml:"jitter,omitempty"`
	// For each retry delay, a random portion of the delay multiplied by the jitterFactor will be added or subtracted to the delay.
	// For example: a retry delay of 100 milliseconds and a jitterFactor of .25 will result in a random retry delay between 75 and 125 milliseconds.
	// Replaces any previously configured jitter duration.
	JitterFactor *float64 `json:"jitterFactor,omitempty" mapstructure:"jitterFactor" yaml:"jitterFactor,omitempty"`
}

HTTPRetryConfig represents retry policy settings.

func (HTTPRetryConfig) Equal

func (rs HTTPRetryConfig) Equal(target HTTPRetryConfig) bool

Equal checks if this instance equals the target.

func (HTTPRetryConfig) IsZero

func (rs HTTPRetryConfig) IsZero() bool

IsZero if the current instance is empty.

func (HTTPRetryConfig) ToRetryPolicy

func (rs HTTPRetryConfig) ToRetryPolicy() (
	retrypolicy.RetryPolicy[*http.Response], error,
)

ToRetryPolicy validates and create the retry policy.

type TLSClientCertificate

type TLSClientCertificate struct {
	// CertFile is the path to the TLS cert to use for TLS required connections.
	CertFile *goenvconf.EnvString `json:"certFile,omitempty" yaml:"certFile,omitempty"`
	// CertPem is alternative to certFile. Provide the certificate contents as a base64-encoded string instead of a filepath.
	CertPem *goenvconf.EnvString `json:"certPem,omitempty" yaml:"certPem,omitempty"`
	// KeyFile is the path to the TLS key to use for TLS required connections.
	KeyFile *goenvconf.EnvString `json:"keyFile,omitempty" yaml:"keyFile,omitempty"`
	// KeyPem is the alternative to keyFile. Provide the key contents as a base64-encoded string instead of a filepath.
	KeyPem *goenvconf.EnvString `json:"keyPem,omitempty" yaml:"keyPem,omitempty"`
}

TLSClientCertificate represents a cert and key pair certificate.

func (TLSClientCertificate) Equal

Equal checks if this instance equals the target.

func (TLSClientCertificate) IsZero

func (tc TLSClientCertificate) IsZero() bool

IsZero checks if the client certificate is empty.

func (TLSClientCertificate) LoadKeyPair

func (tc TLSClientCertificate) LoadKeyPair() (*tls.Certificate, error)

LoadKeyPair loads the X509 key pair from configurations.

type TLSConfig

type TLSConfig struct {
	// RootCAFile represents paths to root certificates. For a client this verifies the server certificate. For a server this verifies client certificates.
	// If empty uses system root CA.
	RootCAFile []goenvconf.EnvString `json:"rootCAFile,omitempty" yaml:"rootCAFile,omitempty"`
	// RootCAPem is the alternative to rootCAFile. Provide the CA cert contents as a base64-encoded string instead of a filepath.
	RootCAPem []goenvconf.EnvString `json:"rootCAPem,omitempty" yaml:"rootCAPem,omitempty"`
	// CAFile is the path to the CA cert. For a client this verifies the server certificate. For a server this verifies client certificates.
	// If empty uses system root CA.
	CAFile []goenvconf.EnvString `json:"caFile,omitempty" yaml:"caFile,omitempty"`
	// CAPem is alternative to caFile. Provide the CA cert contents as a base64-encoded string instead of a filepath.
	CAPem []goenvconf.EnvString `json:"caPem,omitempty" yaml:"caPem,omitempty"`
	// Certificates contains the list of client certificates.
	Certificates []TLSClientCertificate `json:"certificates,omitempty" yaml:"certificates,omitempty"`
	// InsecureSkipVerify you can configure TLS to be enabled but skip verifying the server's certificate chain.
	InsecureSkipVerify *goenvconf.EnvBool `json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify,omitempty"`
	// IncludeSystemCACertsPool whether to load the system certificate authorities pool alongside the certificate authority.
	IncludeSystemCACertsPool *goenvconf.EnvBool `json:"includeSystemCACertsPool,omitempty" yaml:"includeSystemCACertsPool,omitempty"`
	// Minimum acceptable TLS version.
	MinVersion string `json:"minVersion,omitempty" yaml:"minVersion,omitempty"`
	// Maximum acceptable TLS version.
	MaxVersion string `json:"maxVersion,omitempty" yaml:"maxVersion,omitempty"`
	// Explicit cipher suites can be set. If left blank, a safe default list is used.
	// See https://go.dev/src/crypto/tls/cipher_suites.go for a list of supported cipher suites.
	CipherSuites []string `json:"cipherSuites,omitempty" yaml:"cipherSuites,omitempty"`
	// ServerName requested by client for virtual hosting.
	// This sets the ServerName in the TLSConfig. Please refer to
	// https://godoc.org/crypto/tls#Config for more information. (optional)
	ServerName *goenvconf.EnvString `json:"serverName,omitempty" yaml:"serverName,omitempty"`
}

TLSConfig represents the transport layer security (LTS) configuration for the mutualTLS authentication.

func (TLSConfig) Equal

func (tc TLSConfig) Equal(target TLSConfig) bool

Equal checks if this instance equals the target.

func (TLSConfig) GetMaxVersion

func (tc TLSConfig) GetMaxVersion() (uint16, error)

GetMaxVersion parses the max TLS version from string.

func (TLSConfig) GetMinVersion

func (tc TLSConfig) GetMinVersion() (uint16, error)

GetMinVersion parses the minx TLS version from string.

func (TLSConfig) Validate

func (tc TLSConfig) Validate() error

Validate if the current instance is valid.

Jump to

Keyboard shortcuts

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