httpc

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Kernel() *resty.Client
	OnBeforeRequest(hooks ...hook.RequestHook) Client
	OnAfterResponse(hooks ...hook.ResponseHook) Client
	NewRequest(ctx context.Context) *resty.Request
}

func GetGlobalClient

func GetGlobalClient() Client

func NewClient

func NewClient(options ...Option) (Client, error)

func NewClientWithConfig

func NewClientWithConfig(config Config) (Client, error)

func NewGlobalClient

func NewGlobalClient(config Config) (Client, error)

NewGlobalClient If there is only one http client, you can select the global client

type Config

type Config struct {
	Host             string        `mapstructure:"host" json:"host"`
	Timeout          time.Duration `mapstructure:"timeout" json:"timeout"`                         // 单位:s
	RetryCount       int           `mapstructure:"retry_count" json:"retry_count"`                 // 重试次数
	RetryWaitTime    time.Duration `mapstructure:"retry_wait_time" json:"retry_wait_time"`         // 重试间隔等待时间, 单位:s
	RetryMaxWaitTime time.Duration `mapstructure:"retry_max_wait_time" json:"retry_max_wait_time"` // 重试间隔最大等待时间, 单位:s
	Alias            string        `mapstructure:"alias" json:"alias"`
}

type Manager

type Manager interface {
	Add(alias string, c Client)
	Delete(alias string)
	Get(alias string) (Client, error)
	Has(alias string) bool
}

func ClientManager

func ClientManager() Manager

type Option

type Option func(*Config)

func WithAlias

func WithAlias(alias string) Option

func WithHost

func WithHost(host string) Option

func WithRetryCount

func WithRetryCount(retryCount int) Option

func WithRetryMaxWaitTime

func WithRetryMaxWaitTime(retryMaxWaitTime time.Duration) Option

func WithRetryWaitTime

func WithRetryWaitTime(retryWaitTime time.Duration) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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