Documentation
¶
Index ¶
- func Delete[T any](ctx context.Context, url string, opts ...RequestOption) (*T, error)
- func Do(ctx context.Context, method, url string, reqBody interface{}, ...) ([]byte, error)
- func Get[T any](ctx context.Context, url string, opts ...RequestOption) (*T, error)
- func GetRealIP(r *http.Request) string
- func Post[T any](ctx context.Context, url string, reqBody interface{}, opts ...RequestOption) (*T, error)
- func Put[T any](ctx context.Context, url string, reqBody interface{}, opts ...RequestOption) (*T, error)
- func SetObject(oj *HttpClient)
- type Component
- type Config
- type HttpClient
- type RequestOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(ctx context.Context, method, url string, reqBody interface{}, opts ...RequestOption) ([]byte, error)
Do 便捷通用请求(全局单例)
func Post ¶
func Post[T any](ctx context.Context, url string, reqBody interface{}, opts ...RequestOption) (*T, error)
Post 便捷 POST 请求(全局单例)
func Put ¶
func Put[T any](ctx context.Context, url string, reqBody interface{}, opts ...RequestOption) (*T, error)
Put 便捷 PUT 请求(全局单例)
func SetObject ¶
func SetObject(oj *HttpClient)
Types ¶
type Config ¶
type Config struct {
Timeout int64 `yaml:"timeout,omitempty"` // 总超时时间(秒,推荐 5-10s)
MaxIdleConns int `yaml:"max_idle_conns,omitempty"` // 最大空闲连接数
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host,omitempty"` // 每个Host最大空闲连接
IdleConnTimeout int64 `yaml:"idle_conn_timeout,omitempty"` // 空闲连接超时(秒)
}
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient() *HttpClient
func (*HttpClient) Close ¶
func (c *HttpClient) Close()
func (*HttpClient) Do ¶
func (c *HttpClient) Do(ctx context.Context, method, url string, reqBody interface{}, opts ...RequestOption) ([]byte, error)
Do 核心请求方法
func (*HttpClient) Init ¶
func (c *HttpClient) Init(cfg *Config) error
type RequestOption ¶
func WithContext ¶
func WithContext(ctx context.Context) RequestOption
func WithHeader ¶
func WithHeader(key, value string) RequestOption
Click to show internal directories.
Click to hide internal directories.