httpclient

package
v0.0.0-...-71969ea Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntityResponse

type EntityResponse struct {
	// Status 表示HTTP响应的状态码。
	Status int `json:"status"`
	// Header 表示HTTP响应的头信息。
	Header http.Header `json:"header"`
	// Body 表示HTTP响应的主体内容,以字节数组的形式存储。
	Body []byte `json:"body"`
}

EntityResponse 表示一个HTTP响应的实体,包含了状态码、响应头和响应体。

func NewEntityResponse

func NewEntityResponse() *EntityResponse

NewEntityResponse 创建一个新的 EntityResponse 实例

func (*EntityResponse) SetBody

func (er *EntityResponse) SetBody(body []byte) *EntityResponse

SetBody 设置 EntityResponse 的响应体

func (*EntityResponse) SetHeader

func (er *EntityResponse) SetHeader(header http.Header) *EntityResponse

SetHeader 设置 EntityResponse 的响应头

func (*EntityResponse) SetStatus

func (er *EntityResponse) SetStatus(status int) *EntityResponse

SetStatus 设置 EntityResponse 的状态码

type HttpClient

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

HttpClient 是一个封装了HTTP客户端功能的结构体

func NewHttpClient

func NewHttpClient(log *zap.Logger) *HttpClient

NewHttpClient 创建一个新的HttpClient实例 参数:

  • log: 用于记录日志的zap.Logger实例
  • timeoutSec: HTTP请求的超时时间(秒)

返回值:

  • *HttpClient: 新创建的HttpClient实例

func (*HttpClient) Send

func (hc *HttpClient) Send(request *http.Request, timeout time.Duration) ([]byte, error)

Send 发送HTTP请求并返回响应体 参数:

  • request: 要发送的HTTP请求对象
  • timeout: 请求超时时间

返回值:

  • []byte: 响应体的字节数据
  • error: 请求过程中可能发生的错误

func (*HttpClient) SendRequestReturnEntity

func (hc *HttpClient) SendRequestReturnEntity(request *http.Request, timeout time.Duration) (*EntityResponse, error)

SendRequestReturnEntity 发送HTTP请求并返回包含详细信息的EntityResponse实体 参数:

  • request: 要发送的HTTP请求对象
  • timeout: 请求超时时间

返回值:

  • *EntityResponse: 包含状态码、响应体和响应头的响应实体
  • error: 请求过程中可能发生的错误

Jump to

Keyboard shortcuts

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