httpClient

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ReadResponseErr    ReadResponseError
	UrlEmptyErr        UrlEmptyError
	GenerateCertErr    GenerateCertError
	GenerateRequestErr GenerateRequestError
	UnmarshalXmlErr    UnmarshalXmlError
	UnmarshalJsonErr   UnmarshalJsonError
	SetSteamBodyErr    SetSteamBodyError
	SetFormBodyErr     SetFormBodyError
	SetXmlBodyErr      SetXmlBodyError
	SetJsonBodyErr     SetJsonBodyError
	WriteResponseErr   WriteResponseError
)
View Source
var (
	ContentTypeJson       ContentType = "json"
	ContentTypeXml        ContentType = "xml"
	ContentTypeForm       ContentType = "form"
	ContentTypeFormData   ContentType = "form-data"
	ContentTypePlain      ContentType = "plain"
	ContentTypeHtml       ContentType = "html"
	ContentTypeCss        ContentType = "css"
	ContentTypeJavascript ContentType = "javascript"
	ContentTypeSteam      ContentType = "steam"

	ContentTypes = map[ContentType]string{
		ContentTypeJson:       "application/json",
		ContentTypeXml:        "application/xml",
		ContentTypeForm:       "application/x-www-form-urlencoded",
		ContentTypeFormData:   "form-data",
		ContentTypePlain:      "text/plain",
		ContentTypeHtml:       "text/html",
		ContentTypeCss:        "text/css",
		ContentTypeJavascript: "text/javascript",
		ContentTypeSteam:      "application/octet-stream",
	}

	AcceptJson       Accept = "json"
	AcceptXml        Accept = "xml"
	AcceptPlain      Accept = "plain"
	AcceptHtml       Accept = "html"
	AcceptCss        Accept = "css"
	AcceptJavascript Accept = "javascript"
	AcceptSteam      Accept = "steam"
	AcceptAny        Accept = "any"

	Accepts = map[Accept]string{
		AcceptJson:       "application/json",
		AcceptXml:        "application/xml",
		AcceptPlain:      "text/plain",
		AcceptHtml:       "text/html",
		AcceptCss:        "text/css",
		AcceptJavascript: "text/javascript",
		AcceptSteam:      "application/octet-stream",
		AcceptAny:        "*/*",
	}
)

Functions

This section is empty.

Types

type Accept

type Accept string

type ContentType

type ContentType string

type GenerateCertError

type GenerateCertError struct{ myError.MyError }

func (*GenerateCertError) Error

func (my *GenerateCertError) Error() string

func (*GenerateCertError) Is

func (my *GenerateCertError) Is(target error) bool

func (*GenerateCertError) New

func (*GenerateCertError) Panic

func (*GenerateCertError) Wrap

type GenerateRequestError

type GenerateRequestError struct{ myError.MyError }

func (*GenerateRequestError) Error

func (my *GenerateRequestError) Error() string

func (*GenerateRequestError) Is

func (my *GenerateRequestError) Is(target error) bool

func (*GenerateRequestError) New

func (*GenerateRequestError) Panic

func (*GenerateRequestError) Wrap

type HttpClient

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

HttpClient http客户端

var App HttpClient

func NewDelete

func NewDelete(url string) *HttpClient

NewDelete 实例化:http客户端delete请求

func NewGet

func NewGet(url string) *HttpClient

NewGet 实例化:http客户端get请求

func NewHttpClient

func NewHttpClient(url string) *HttpClient

NewHttpClient 实例化:http客户端

func NewPost

func NewPost(url string) *HttpClient

NewPost 实例化:http客户端post请求

func NewPut

func NewPut(url string) *HttpClient

NewPut 实例化:http客户端put请求

func (*HttpClient) AddHeaders

func (my *HttpClient) AddHeaders(headers map[string][]string) *HttpClient

AddHeaders 追加请求头

func (*HttpClient) AppendHeaderAccept

func (my *HttpClient) AppendHeaderAccept(keys ...Accept) *HttpClient

AppendHeaderAccept 追加请求头接受内容类型

func (*HttpClient) AppendHeaderContentType

func (my *HttpClient) AppendHeaderContentType(keys ...ContentType) *HttpClient

AppendHeaderContentType 追加请求头内容类型

func (*HttpClient) Download

func (my *HttpClient) Download(filename string) *HttpClientDownload

Download 使用下载器下载文件

func (*HttpClient) GenerateRequest

func (my *HttpClient) GenerateRequest() *HttpClient

GenerateRequest 生成请求对象

func (*HttpClient) GetRequest

func (my *HttpClient) GetRequest() *http.Request

GetRequest 获取请求

func (*HttpClient) GetResponse

func (my *HttpClient) GetResponse() *http.Response

GetResponse 获取响应对象

func (*HttpClient) GetResponseJsonBody

func (my *HttpClient) GetResponseJsonBody(target any, keys ...any) *HttpClient

GetResponseJsonBody 获取json格式响应体

func (*HttpClient) GetResponseRawBody

func (my *HttpClient) GetResponseRawBody() []byte

GetResponseRawBody 获取原始响应体

func (*HttpClient) GetResponseXmlBody

func (my *HttpClient) GetResponseXmlBody(target any) *HttpClient

GetResponseXmlBody 获取xml格式响应体

func (*HttpClient) New

func (*HttpClient) New(url string) *HttpClient

func (*HttpClient) NewDelete

func (*HttpClient) NewDelete(url string) *HttpClient

func (*HttpClient) NewGet

func (*HttpClient) NewGet(url string) *HttpClient

func (*HttpClient) NewPost

func (*HttpClient) NewPost(url string) *HttpClient

func (*HttpClient) NewPut

func (*HttpClient) NewPut(url string) *HttpClient

func (*HttpClient) ParseByContentType

func (my *HttpClient) ParseByContentType(target any) *HttpClient

ParseByContentType 根据响应头Content-Type自动解析响应体

func (*HttpClient) SaveResponseSteamFile

func (my *HttpClient) SaveResponseSteamFile(filename string) *HttpClient

SaveResponseSteamFile 保存二进制到文件

func (*HttpClient) Send

func (my *HttpClient) Send() *HttpClient

Send 发送请求

func (*HttpClient) SetAuthorization

func (my *HttpClient) SetAuthorization(username, password, title string) *HttpClient

SetAuthorization 设置认证

func (*HttpClient) SetBody

func (my *HttpClient) SetBody(body []byte) *HttpClient

SetBody 设置请求体

func (*HttpClient) SetCert

func (my *HttpClient) SetCert(filename string) *HttpClient

SetCert 设置SSL证书

func (*HttpClient) SetCssBody

func (my *HttpClient) SetCssBody(text string) *HttpClient

SetCssBody 设置Css请求体

func (*HttpClient) SetFormBody

func (my *HttpClient) SetFormBody(body map[string]string) *HttpClient

SetFormBody 设置表单请求体

func (*HttpClient) SetFormDataBody

func (my *HttpClient) SetFormDataBody(texts map[string]string, files map[string]string) *HttpClient

SetFormDataBody 设置表单数据请求体

func (*HttpClient) SetHeaderAccept

func (my *HttpClient) SetHeaderAccept(key Accept) *HttpClient

SetHeaderAccept 设置请求头接受内容类型

func (*HttpClient) SetHeaderContentType

func (my *HttpClient) SetHeaderContentType(key ContentType) *HttpClient

SetHeaderContentType 设置请求头内容类型

func (*HttpClient) SetHeaders

func (my *HttpClient) SetHeaders(headers map[string][]string) *HttpClient

SetHeaders 设置请求头

func (*HttpClient) SetHtmlBody

func (my *HttpClient) SetHtmlBody(text string) *HttpClient

SetHtmlBody 设置html请求体

func (*HttpClient) SetJavascriptBody

func (my *HttpClient) SetJavascriptBody(text string) *HttpClient

SetJavascriptBody 设置Javascript请求体

func (*HttpClient) SetJsonBody

func (my *HttpClient) SetJsonBody(body any) *HttpClient

SetJsonBody 设置json请求体

func (*HttpClient) SetMethod

func (my *HttpClient) SetMethod(method string) *HttpClient

SetMethod 设置请求方法

func (*HttpClient) SetPlainBody

func (my *HttpClient) SetPlainBody(text string) *HttpClient

SetPlainBody 设置纯文本请求体

func (*HttpClient) SetQueries

func (my *HttpClient) SetQueries(queries map[string]string) *HttpClient

SetQueries 设置请求参数

func (*HttpClient) SetSteamBody

func (my *HttpClient) SetSteamBody(filename string) *HttpClient

SetSteamBody 设置二进制文件

func (*HttpClient) SetTimeoutSecond

func (my *HttpClient) SetTimeoutSecond(timeoutSecond int64) *HttpClient

SetTimeoutSecond 设置超时

func (*HttpClient) SetUrl

func (my *HttpClient) SetUrl(url string) *HttpClient

SetUrl 设置请求地址

func (*HttpClient) SetXmlBody

func (my *HttpClient) SetXmlBody(body any) *HttpClient

SetXmlBody 设置xml请求体

type HttpClientDownload

type HttpClientDownload struct {
	// contains filtered or unexported fields
}
var HttpClientDownloadApp HttpClientDownload

func (*HttpClientDownload) New

func (*HttpClientDownload) New(httpClient *HttpClient, filename string) *HttpClientDownload

New 实例化http客户端下载器

func (*HttpClientDownload) SaveLocal

func (my *HttpClientDownload) SaveLocal() *HttpClient

Save 保存到本地

func (*HttpClientDownload) SendResponse

func (my *HttpClientDownload) SendResponse(w http.ResponseWriter, headers map[string][]string) *HttpClient

Send 发送到客户端

func (*HttpClientDownload) SetProcessContent

func (my *HttpClientDownload) SetProcessContent(processContent string) *HttpClientDownload

SetProcessContent 设置终端进度条标题

type Multiple

type Multiple struct {
	// contains filtered or unexported fields
}
var MultipleApp Multiple

func NewMultiple

func NewMultiple() *Multiple

NewMultiple 实例化:批量请求对象

func (*Multiple) Append

func (my *Multiple) Append(hc *HttpClient) *Multiple

Append 添加httpClient对象

func (*Multiple) GetClients

func (my *Multiple) GetClients() []*HttpClient

GetClients 获取链接池

func (*Multiple) New

func (*Multiple) New() *Multiple

func (*Multiple) Send

func (my *Multiple) Send() *Multiple

Send 批量发送

func (*Multiple) SetClients

func (my *Multiple) SetClients(clients []*HttpClient) *Multiple

SetClients 设置httpClient对象

type ReadResponseError

type ReadResponseError struct{ myError.MyError }

func (*ReadResponseError) Error

func (my *ReadResponseError) Error() string

func (*ReadResponseError) Is

func (my *ReadResponseError) Is(target error) bool

func (*ReadResponseError) New

func (*ReadResponseError) Panic

func (*ReadResponseError) Wrap

type SetFormBodyError

type SetFormBodyError struct{ myError.MyError }

func (*SetFormBodyError) Error

func (my *SetFormBodyError) Error() string

func (*SetFormBodyError) Is

func (my *SetFormBodyError) Is(target error) bool

func (*SetFormBodyError) New

func (*SetFormBodyError) Panic

func (*SetFormBodyError) Wrap

type SetJsonBodyError

type SetJsonBodyError struct{ myError.MyError }

func (*SetJsonBodyError) Error

func (my *SetJsonBodyError) Error() string

func (*SetJsonBodyError) Is

func (my *SetJsonBodyError) Is(target error) bool

func (*SetJsonBodyError) New

func (*SetJsonBodyError) Panic

func (*SetJsonBodyError) Wrap

type SetSteamBodyError

type SetSteamBodyError struct{ myError.MyError }

func (*SetSteamBodyError) Error

func (my *SetSteamBodyError) Error() string

func (*SetSteamBodyError) Is

func (my *SetSteamBodyError) Is(target error) bool

func (*SetSteamBodyError) New

func (*SetSteamBodyError) Panic

func (*SetSteamBodyError) Wrap

type SetXmlBodyError

type SetXmlBodyError struct{ myError.MyError }

func (*SetXmlBodyError) Error

func (my *SetXmlBodyError) Error() string

func (*SetXmlBodyError) Is

func (my *SetXmlBodyError) Is(target error) bool

func (*SetXmlBodyError) New

func (*SetXmlBodyError) Panic

func (*SetXmlBodyError) Panic() myError.IMyError

func (*SetXmlBodyError) Wrap

type UnmarshalJsonError

type UnmarshalJsonError struct{ myError.MyError }

func (*UnmarshalJsonError) Error

func (my *UnmarshalJsonError) Error() string

func (*UnmarshalJsonError) Is

func (my *UnmarshalJsonError) Is(target error) bool

func (*UnmarshalJsonError) New

func (*UnmarshalJsonError) Panic

func (*UnmarshalJsonError) Wrap

type UnmarshalXmlError

type UnmarshalXmlError struct{ myError.MyError }

func (*UnmarshalXmlError) Error

func (my *UnmarshalXmlError) Error() string

func (*UnmarshalXmlError) Is

func (my *UnmarshalXmlError) Is(target error) bool

func (*UnmarshalXmlError) New

func (*UnmarshalXmlError) Panic

func (*UnmarshalXmlError) Wrap

type UrlEmptyError

type UrlEmptyError struct{ myError.MyError }

func (*UrlEmptyError) Error

func (my *UrlEmptyError) Error() string

func (*UrlEmptyError) Is

func (my *UrlEmptyError) Is(target error) bool

func (*UrlEmptyError) New

func (*UrlEmptyError) Panic

func (*UrlEmptyError) Panic() myError.IMyError

func (*UrlEmptyError) Wrap

func (*UrlEmptyError) Wrap(err error) myError.IMyError

type WriteResponseError

type WriteResponseError struct{ myError.MyError }

func (*WriteResponseError) Error

func (my *WriteResponseError) Error() string

func (*WriteResponseError) Is

func (my *WriteResponseError) Is(target error) bool

func (*WriteResponseError) New

func (*WriteResponseError) Panic

func (*WriteResponseError) Wrap

Jump to

Keyboard shortcuts

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