dialer

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResponseIsNil = errors.New("'response' from downstream is nil")
	ErrExec          = errors.New("executor failed")
)

Error response

View Source
var (
	ErrInternalServer = errors.New("internal server error, response code > 500")
	ErrNotFound       = errors.New("resource not found, response code = 404")
	ErrDialer         = errors.New("dialer Error")
)

Validator Errors

Functions

This section is empty.

Types

type Conf

type Conf struct {
	Tr TransportConf
	Nw NetworkConf
	To TimeoutConf
}

type Dialer

type Dialer interface {
	Dial(
		context.Context,
		*http.Request,
	) (*http.Response, error)
}

Dialer interface defines the dialer for a downstream request

func NewDefaultDialer

func NewDefaultDialer(logger log.Logger, conf *Conf) (Dialer, error)

NewDefaultDialer returns new default http dialer

func NewDialer

func NewDialer(logger log.Logger, opts ...Option) (Dialer, error)

NewDialer ...

func NewTimedDialer

func NewTimedDialer(logger log.Logger, conf *Conf) (Dialer, error)

NewTimedDialer returns the dialer which times out

type NetworkConf

type NetworkConf struct {
	// Timeout 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.
	Timeout int

	// KeepAlive specifies the keep-alive period for an active
	// network connection.
	// If zero, keep-alives are enabled if supported by the protocol
	// and operating system. Network protocols or operating systems
	// that do not support keep-alives ignore this field.
	// If negative, keep-alives are disabled.
	KeepAlive int
}

type Option

type Option func(*defaultDialer) error

Option sets optional parameters for dailer

func WithCustomValidator

func WithCustomValidator(
	fn func(
		context.Context, *http.Request, *http.Response, error,
	) error,
) Option

WithCustomValidator sets custom validator to list of existing validator

func WithDefaultExecutor

func WithDefaultExecutor() Option

WithDefaultExecutor uses default http.DefaultTransport for round trip

func WithDefaultValidators

func WithDefaultValidators() Option

WithDefaultValidators sets the validators for the dialer

func WithRequestOption

func WithRequestOption(fn RequestOption) Option

WithRequestOption sets a custom request option for request

func WithResponseOption

func WithResponseOption(fn ResponseOption) Option

WithResponseOption sets a custom response option for request

func WithRetrierExecutor

func WithRetrierExecutor(
	logger log.Logger,
	opts ...retrier.RetrierOption,
) Option

func WithRoundTripperExecutor

func WithRoundTripperExecutor(cfg *Conf) Option

WithRoundTripperExecutor executor which uses a custom round tripper built from configurations to call downstream

func WithTimeoutExecutor

func WithTimeoutExecutor(cfg *TimeoutConf) Option

WithTimeoutExecutor sets a custom executor which has very short timeout

type RequestOption

type RequestOption func(context.Context, *http.Request)

RequestOption ...

type ResponseOption

type ResponseOption func(context.Context, *http.Request, *http.Response)

ResponseOption ...

type TimeoutConf

type TimeoutConf struct {
	Tm int //in millisecond
}

type TransportConf

type TransportConf struct {
	// MaxIdleConns controls the maximum number of idle (keep-alive)
	// connections across all hosts. Zero means no limit.
	MaxIdleConns int

	// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
	// (keep-alive) connections to keep per-host.
	MaxIdleConnsPerHost int

	// MaxConnsPerHost optionally limits the total number of
	// connections per host, including connections in the dialing,
	// active, and idle states. On limit violation, dials will block.
	//
	// Zero means no limit.
	MaxConnsPerHost int

	// IdleConnTimeout is the maximum amount of time an idle
	// IdleConnTimeout is the maximum amount of time an idle
	// itself.
	// Zero means no limit.
	IdleConnTimeout int
}

Jump to

Keyboard shortcuts

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