httpcli

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v1.1.80

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

Client 封装了resty客户端

func New

func New(opts ...Option) *Client

New 创建新的HTTP客户端

func (*Client) Request added in v1.1.80

func (c *Client) Request(ctx context.Context) *Request

Request 创建新请求

type ErrorResponse added in v1.1.80

type ErrorResponse struct {
	StatusCode int
	Message    string
	Body       []byte
}

ErrorResponse 错误响应结构

func (*ErrorResponse) Error added in v1.1.80

func (e *ErrorResponse) Error() string

Error 实现error接口

func (*ErrorResponse) Is added in v1.1.80

func (e *ErrorResponse) Is(target error) bool

Is 错误比较

type Option

type Option func(*Client)

Option 客户端配置选项

func WithBaseURL added in v1.1.80

func WithBaseURL(baseURL string) Option

WithBaseURL 设置基础URL

func WithClientCert added in v1.1.80

func WithClientCert(certPath, keyPath string) Option

WithClientCert 加载客户端证书和私钥

func WithCookieJar added in v1.1.80

func WithCookieJar() Option

WithCookieJar 启用Cookie管理

func WithDebug added in v1.1.80

func WithDebug(enable bool) Option

WithDebug 启用调试模式

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders 设置公共请求头

func WithInsecureSkipVerify added in v1.1.80

func WithInsecureSkipVerify() Option

WithInsecureSkipVerify 跳过证书验证(仅用于测试环境)

func WithProxy added in v1.1.80

func WithProxy(proxyURL string) Option

WithProxy 设置代理

func WithRetry added in v1.1.80

func WithRetry(count int, waitTime, maxWaitTime time.Duration) Option

WithRetry 设置重试策略

func WithRootCA added in v1.1.80

func WithRootCA(caCertPath string) Option

WithRootCA 从文件加载根证书

func WithTLSConfig added in v1.1.80

func WithTLSConfig(tlsConfig *tls.Config) Option

WithTLSConfig 设置TLS配置

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置超时时间

func WithTransport added in v1.1.80

func WithTransport(transport *http.Transport) Option

WithTransport 设置自定义 Transport

type Request

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

Request 请求构建器

func (*Request) Delete added in v1.1.80

func (r *Request) Delete(url string) (*Response, error)

Delete 发送DELETE请求

func (*Request) Get added in v1.1.80

func (r *Request) Get(url string) (*Response, error)

Get 发送GET请求

func (*Request) Patch added in v1.1.80

func (r *Request) Patch(url string) (*Response, error)

Patch 发送PATCH请求

func (*Request) Post added in v1.1.80

func (r *Request) Post(url string) (*Response, error)

Post 发送POST请求

func (*Request) Put added in v1.1.80

func (r *Request) Put(url string) (*Response, error)

Put 发送PUT请求

func (*Request) SetAuthToken added in v1.1.80

func (r *Request) SetAuthToken(token string) *Request

SetAuthToken 设置Bearer Token

func (*Request) SetBody

func (r *Request) SetBody(body interface{}) *Request

SetBody 设置请求体

func (*Request) SetError added in v1.1.80

func (r *Request) SetError(err interface{}) *Request

SetError 设置错误解析目标

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string) *Request

SetHeader 设置请求头

func (*Request) SetHeaders

func (r *Request) SetHeaders(headers map[string]string) *Request

SetHeaders 批量设置请求头

func (*Request) SetQueryParam added in v1.1.80

func (r *Request) SetQueryParam(key, value string) *Request

SetQueryParam 设置查询参数

func (*Request) SetQueryParams added in v1.1.80

func (r *Request) SetQueryParams(params map[string]string) *Request

SetQueryParams 批量设置查询参数

func (*Request) SetResult added in v1.1.80

func (r *Request) SetResult(result interface{}) *Request

SetResult 设置响应结果解析目标

type Response

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

Response 封装响应

func (*Response) Body added in v1.1.80

func (r *Response) Body() []byte

Body 获取原始响应体

func (*Response) Headers added in v1.1.80

func (r *Response) Headers() http.Header

Headers 获取响应头

func (*Response) IsError added in v1.1.80

func (r *Response) IsError() bool

IsError 判断请求是否失败

func (*Response) IsSuccess added in v1.1.80

func (r *Response) IsSuccess() bool

IsSuccess 判断请求是否成功

func (*Response) StatusCode added in v1.1.80

func (r *Response) StatusCode() int

StatusCode 获取状态码

func (*Response) String added in v1.1.80

func (r *Response) String() string

String 获取字符串格式响应体

func (*Response) UnmarshalJSON added in v1.1.80

func (r *Response) UnmarshalJSON(v interface{}) error

UnmarshalJSON 解析JSON响应体

Jump to

Keyboard shortcuts

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