httputil

package
v0.0.0-...-5a6988a Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package httputil 是一个 http client 辅助类,基于 Resty 库实现

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = New()
View Source
var DefaultDownloadClient = NewDownload()
View Source
var DefaultSSEClient = NewSSE()

Functions

func Download

func Download(url, output string, callbacks ...Callback) error

Download 下载文件,存入 output 表示的文件中

func Get

func Get(url string, callbacks ...Callback) error

Get 发送 HTTP/GET 请求,成功时回调 callbacks

func GetQuery

func GetQuery(url string, query map[string]string, callbacks ...Callback) error

GetQuery 发送 HTTP/GET 请求,query 参数通过 map 传递进来,成功时回调 callbacks

func GetQueryWithContext

func GetQueryWithContext(ctx context.Context, url string, query map[string]string, callbacks ...Callback) error

GetQueryWithContext 发送 HTTP/GET 请求,query 参数通过 map 传递进来,成功时回调 callbacks 支持 context

func GetTopDomain

func GetTopDomain(host string) string

func GetWithContext

func GetWithContext(ctx context.Context, url string, callbacks ...Callback) error

GetWithContext 发送 HTTP/GET 请求,成功时回调 callbacks 支持 context

func New

func New() *httpClient

func NewDownload

func NewDownload() *downloadHttpClient

func NewSSE

func NewSSE() *sseHttpClient

func PostForm

func PostForm(url string, data map[string]string, callbacks ...Callback) error

PostForm 发送 HTTP/POST 请求,数据格式 x-www-form-urlencoded ,成功时回调 callbacks

func PostFormWithContext

func PostFormWithContext(ctx context.Context, url string, data map[string]string, callbacks ...Callback) error

PostFormWithContext 发送 HTTP/POST 请求,数据格式 x-www-form-urlencoded ,成功时回调 callbacks 支持 context

func PostGzJSON

func PostGzJSON(url string, body any, callbacks ...Callback) error

func PostGzJSONWithContext

func PostGzJSONWithContext(ctx context.Context, url string, body any, callbacks ...Callback) error

PostJSONWithContext 发送 HTTP/POST 请求,数据格式 JSON ,成功时回调 callbacks 支持 context

func PostJSON

func PostJSON(url string, body any, callbacks ...Callback) error

PostJSON 发送 HTTP/POST 请求,数据格式 JSON ,成功时回调 callbacks Supported request body data types is `string`, `[]byte`, `struct`, `map`, `slice` and `io.Reader`. Body value can be pointer or non-pointer. Automatic marshalling for JSON and XML content type, if it is `struct`, `map`, or `slice`.

func PostJSONWithContext

func PostJSONWithContext(ctx context.Context, url string, body any, callbacks ...Callback) error

PostJSONWithContext 发送 HTTP/POST 请求,数据格式 JSON ,成功时回调 callbacks 支持 context

func SSEPostJSON

func SSEPostJSON(url string, body any, callbacks ...Callback) (string, error)

func SSEPostJSONWithContext

func SSEPostJSONWithContext(ctx context.Context, url string, body any, callbacks ...Callback) (string, error)

Types

type Builder

type Builder struct {
	strings.Builder
	// contains filtered or unexported fields
}

func (*Builder) Write

func (b *Builder) Write(p []byte) (n int, err error)

type Callback

type Callback func([]byte) error

type OpenAPIClient

type OpenAPIClient struct {
	*http.Client
	APPkey string
	Secert string
}

func NewOpenAPIClient

func NewOpenAPIClient(APPkey string, Secert string) *OpenAPIClient

func (*OpenAPIClient) Get

func (o *OpenAPIClient) Get(requestUrl string, params url.Values) ([]byte, error)

func (*OpenAPIClient) PostFile

func (o *OpenAPIClient) PostFile(requestUrl string, params url.Values, path string) ([]byte, error)

func (*OpenAPIClient) PostForm

func (o *OpenAPIClient) PostForm(requestUrl string, params url.Values, form map[string]string) ([]byte, error)

func (*OpenAPIClient) PostJson

func (o *OpenAPIClient) PostJson(requestUrl string, params url.Values, jsonData map[string]interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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