config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetPreDefinedOpts

func SetPreDefinedOpts(opts ...RequestOption)

SetPreDefinedOpts Pre define some RequestOption here

Types

type ClientOption

type ClientOption struct {
	F func(o *ClientOptions)
}

ClientOption is the only struct that can be used to set ClientOptions.

type ClientOptions

type ClientOptions struct {
	// Timeout for establishing a connection to server
	DialTimeout time.Duration
	// The max connection nums for each host
	MaxConnsPerHost int

	MaxIdleConnDuration time.Duration
	MaxConnDuration     time.Duration
	MaxConnWaitTimeout  time.Duration
	KeepAlive           bool
	ReadTimeout         time.Duration
	TLSConfig           *tls.Config
	ResponseBodyStream  bool

	// Client name. Used in User-Agent request header.
	//
	// Default client name is used if not set.
	Name string

	// NoDefaultUserAgentHeader when set to true, causes the default
	// User-Agent header to be excluded from the Request.
	NoDefaultUserAgentHeader bool

	// Dialer is the custom dialer used to establish connection.
	// Default Dialer is used if not set.
	Dialer network.Dialer

	// Attempt to connect to both ipv4 and ipv6 addresses if set to true.
	//
	// This option is used only if default TCP dialer is used,
	// i.e. if Dialer is blank.
	//
	// By default client connects only to ipv4 addresses,
	// since unfortunately ipv6 remains broken in many networks worldwide :)
	DialDualStack bool

	// Maximum duration for full request writing (including body).
	//
	// By default request write timeout is unlimited.
	WriteTimeout time.Duration

	// Maximum response body size.
	//
	// The client returns ErrBodyTooLarge if this limit is greater than 0
	// and response body is greater than the limit.
	//
	// By default response body size is unlimited.
	MaxResponseBodySize int

	// Header names are passed as-is without normalization
	// if this option is set.
	//
	// Disabled header names' normalization may be useful only for proxying
	// responses to other clients expecting case-sensitive header names.
	//
	// By default request and response header names are normalized, i.e.
	// The first letter and the first letters following dashes
	// are uppercased, while all the other letters are lowercased.
	// Examples:
	//
	//     * HOST -> Host
	//     * content-type -> Content-Type
	//     * cONTENT-lenGTH -> Content-Length
	DisableHeaderNamesNormalizing bool

	// Path values are sent as-is without normalization
	//
	// Disabled path normalization may be useful for proxying incoming requests
	// to servers that are expecting paths to be forwarded as-is.
	//
	// By default path values are normalized, i.e.
	// extra slashes are removed, special characters are encoded.
	DisablePathNormalizing bool

	// all configurations related to retry
	RetryConfig *retry.Config

	HostClientStateObserve HostClientStateFunc

	// StateObserve execution interval
	ObservationInterval time.Duration

	// Callback hook for re-configuring host client
	// If an error is returned, the request will be terminated.
	HostClientConfigHook func(hc interface{}) error
}

func NewClientOptions

func NewClientOptions(opts []ClientOption) *ClientOptions

func (*ClientOptions) Apply

func (o *ClientOptions) Apply(opts []ClientOption)

type ConnPoolState

type ConnPoolState struct {
	// The conn num of conn pool. These conns are idle connections.
	PoolConnNum int
	// Total conn num.
	TotalConnNum int
	// Number of pending connections
	WaitConnNum int
	// HostClient Addr
	Addr string
}

type HostClientState

type HostClientState interface {
	ConnPoolState() ConnPoolState
}

type HostClientStateFunc

type HostClientStateFunc func(HostClientState)

type Option

type Option struct {
	F func(o *Options)
}

Option is the only struct that can be used to set Options.

type Options

type Options struct {
	KeepAliveTimeout             time.Duration
	ReadTimeout                  time.Duration
	WriteTimeout                 time.Duration
	IdleTimeout                  time.Duration
	RedirectTrailingSlash        bool
	MaxRequestBodySize           int
	MaxKeepBodySize              int
	GetOnly                      bool
	DisableKeepalive             bool
	RedirectFixedPath            bool
	HandleMethodNotAllowed       bool
	UseRawPath                   bool
	RemoveExtraSlash             bool
	UnescapePathValues           bool
	DisablePreParseMultipartForm bool
	StreamRequestBody            bool
	NoDefaultServerHeader        bool
	DisablePrintRoute            bool
	Network                      string
	Addr                         string
	BasePath                     string
	ExitWaitTimeout              time.Duration
	TLS                          *tls.Config
	H2C                          bool
	ReadBufferSize               int
	ALPN                         bool
	Tracers                      []interface{}
	TraceLevel                   interface{}
	ListenConfig                 *net.ListenConfig
	BindConfig                   interface{}
	ValidateConfig               interface{}
	CustomBinder                 interface{}
	CustomValidator              interface{}

	// TransporterNewer is the function to create a transporter.
	TransporterNewer    func(opt *Options) network.Transporter
	AltTransporterNewer func(opt *Options) network.Transporter

	// In netpoll library, OnAccept is called after connection accepted
	// but before adding it to epoll. OnConnect is called after adding it to epoll.
	// The difference is that onConnect can get data but OnAccept cannot.
	// If you'd like to check whether the peer IP is in the blacklist, you can use OnAccept.
	// In go net, OnAccept is executed after connection accepted but before establishing
	// tls connection. OnConnect is executed after establishing tls connection.
	OnAccept  func(conn net.Conn) context.Context
	OnConnect func(ctx context.Context, conn network.Conn) context.Context

	// Registry is used for service registry.
	Registry registry.Registry
	// RegistryInfo is base info used for service registry.
	RegistryInfo *registry.Info

	AutoReloadRender bool
	// If AutoReloadInterval is set to 0(default).
	// The HTML template will reload according to files' changing event
	// otherwise it will reload after AutoReloadInterval.
	AutoReloadInterval time.Duration

	// Header names are passed as-is without normalization
	// if this option is set.
	//
	// Disabled header names' normalization may be useful only for proxying
	// responses to other clients expecting case-sensitive header names.
	//
	// By default, request and response header names are normalized, i.e.
	// The first letter and the first letters following dashes
	// are uppercased, while all the other letters are lowercased.
	// Examples:
	//
	//     * HOST -> Host
	//     * content-type -> Content-Type
	//     * cONTENT-lenGTH -> Content-Length
	DisableHeaderNamesNormalizing bool
}

func NewOptions

func NewOptions(opts []Option) *Options

func (*Options) Apply

func (o *Options) Apply(opts []Option)

type RequestOption

type RequestOption struct {
	F func(o *RequestOptions)
}

RequestOption is the only struct to set request-level options.

func WithDialTimeout

func WithDialTimeout(t time.Duration) RequestOption

WithDialTimeout sets dial timeout.

This is the request level configuration. It has a higher priority than the client level configuration Note: it won't take effect in the case of the number of connections in the connection pool exceeds the maximum number of connections and needs to establish a connection while waiting.

func WithReadTimeout

func WithReadTimeout(t time.Duration) RequestOption

WithReadTimeout sets read timeout.

This is the request level configuration. It has a higher priority than the client level configuration

func WithRequestTimeout

func WithRequestTimeout(t time.Duration) RequestOption

WithRequestTimeout sets whole request timeout. If it reaches timeout, the client will return.

This is the request level configuration.

func WithSD

func WithSD(b bool) RequestOption

WithSD set isSD in RequestOptions.

func WithTag

func WithTag(k, v string) RequestOption

WithTag set tag in RequestOptions.

func WithWriteTimeout

func WithWriteTimeout(t time.Duration) RequestOption

WithWriteTimeout sets write timeout.

This is the request level configuration. It has a higher priority than the client level configuration

type RequestOptions

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

func NewRequestOptions

func NewRequestOptions(opts []RequestOption) *RequestOptions

NewRequestOptions create a *RequestOptions according to the given opts.

func (*RequestOptions) Apply

func (o *RequestOptions) Apply(opts []RequestOption)

func (*RequestOptions) CopyTo

func (o *RequestOptions) CopyTo(dst *RequestOptions)

func (*RequestOptions) DialTimeout

func (o *RequestOptions) DialTimeout() time.Duration

func (*RequestOptions) IsSD

func (o *RequestOptions) IsSD() bool

func (*RequestOptions) ReadTimeout

func (o *RequestOptions) ReadTimeout() time.Duration

func (*RequestOptions) RequestTimeout

func (o *RequestOptions) RequestTimeout() time.Duration

func (*RequestOptions) StartRequest

func (o *RequestOptions) StartRequest()

StartRequest records the start time of the request.

Note: Users should not call this method.

func (*RequestOptions) StartTime

func (o *RequestOptions) StartTime() time.Time

func (*RequestOptions) Tag

func (o *RequestOptions) Tag(k string) string

func (*RequestOptions) Tags

func (o *RequestOptions) Tags() map[string]string

func (*RequestOptions) WriteTimeout

func (o *RequestOptions) WriteTimeout() time.Duration

Jump to

Keyboard shortcuts

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