http_utils

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnrecognizedEncoding = errors.New("unrecognized encoding string")
)

Functions

This section is empty.

Types

type FileUploadMeta

type FileUploadMeta struct {
	Data []byte // 文件内容
	Src  string // 文件路径
	Name string // 文件名
	MIME string // 文件类型 默认 application/octet-stream
}

FileUploadMeta 文件上传数据

func File

func File(filename string, data []byte) *FileUploadMeta

File 创建文件上传数据

func FileFromPath

func FileFromPath(src string) *FileUploadMeta

FileFromPath 创建文件上传数据

func (*FileUploadMeta) SetMIME

func (f *FileUploadMeta) SetMIME(mime string) *FileUploadMeta

SetMIME 设置文件类型

func (*FileUploadMeta) SetSrc

func (f *FileUploadMeta) SetSrc(src string) *FileUploadMeta

SetSrc 设置文件路径

type HttpHeader

type HttpHeader struct {
	Params             map[string]string // URL 查询参数
	Data               map[string]string // 表单数据
	Headers            map[string]string // 自定义请求头
	Cookies            map[string]string // Cookie设置
	Auth               map[string]string // Basic Auth 认证
	JSON               map[string]any    // JSON 数据体
	Files              map[string]any    // 文件上传字段
	RowData            string            // 原始请求体
	Proxy              string            // 代理地址
	AllowRedirect      bool              // 是否允许重定向
	Timeout            int64             // 请求超时时间 单位-秒
	Chunked            bool              // 是否启用 chunked 模式(不设置 Content-Length)
	DisableKeepalives  bool              // 是否禁用 Keep-Alive
	DisableCompression bool              // 是否禁用压缩
	SkipVerifyTLS      bool              // 是否跳过 TLS 验证
}

HttpHeader for request options

type RequestHookFunc

type RequestHookFunc func(r *http.Request) error

RequestHookFunc request hook

type Response

type Response struct {
	*http.Response

	Text  string
	Bytes []byte
	// contains filtered or unexported fields
}

Response 响应对象 wrapper for http.Response

func Delete

func Delete(url string, options *HttpHeader) (*http.Request, *Response, error)

Delete 删除请求

func Get

func Get(url string, options *HttpHeader) (*http.Request, *Response, error)

Get 请求

func Head(url string, options *HttpHeader) (*http.Request, *Response, error)

Head 请求

func NewResponse

func NewResponse(r *http.Response) (*Response, error)

NewResponse 创建一个响应对象

func Options

func Options(url string, options *HttpHeader) (*http.Request, *Response, error)

Options 获取请求

func Patch

func Patch(url string, options *HttpHeader) (*http.Request, *Response, error)

Patch 请求

func Post

func Post(url string, options *HttpHeader) (*http.Request, *Response, error)

Post 请求

func Put

func Put(url string, options *HttpHeader) (*http.Request, *Response, error)

Put 请求

func (*Response) GetEncoding

func (r *Response) GetEncoding() string

GetEncoding 获取响应编码

func (*Response) JSON

func (r *Response) JSON(v any) error

JSON 解析响应数据为 JSON 这里不一定是 application/json 因为是直接对body数据进行解析

func (*Response) SaveFile

func (r *Response) SaveFile(filename string) error

SaveFile 保存响应数据到文件

func (*Response) SetEncoding

func (r *Response) SetEncoding(e string) error

SetEncoding 设置响应编码

type ResponseHookFunc

type ResponseHookFunc func(r *http.Response) error

ResponseHookFunc response hook

type Session

type Session struct {
	Client *http.Client
	// contains filtered or unexported fields
}

Session http session

func NewSession

func NewSession() *Session

NewSession new session

func (*Session) AddRequestHooks

func (s *Session) AddRequestHooks(hooks ...RequestHookFunc) error

AddRequestHooks 添加请求钩子函数

func (*Session) AddResponseHooks

func (s *Session) AddResponseHooks(hooks ...ResponseHookFunc) error

AddResponseHooks 添加响应钩子函数

func (*Session) Delete

func (s *Session) Delete(urlStr string, options *HttpHeader) (*http.Request, *Response, error)

Delete 使用delete请求

func (*Session) Get

func (s *Session) Get(urlStr string, options *HttpHeader) (*http.Request, *Response, error)

Get 使用get请求

func (*Session) Head

func (s *Session) Head(urlStr string, options *HttpHeader) (*http.Request, *Response, error)

Head 使用head请求

func (*Session) Options

func (s *Session) Options(urlStr string, options *HttpHeader) (*http.Request, *Response, error)

Options 使用options请求

func (*Session) Patch

func (s *Session) Patch(urlStr string, options *HttpHeader) (*http.Request, *Response, error)

Patch 使用patch请求

func (*Session) Post

func (s *Session) Post(urlStr string, options *HttpHeader) (*http.Request, *Response, error)

Post 使用post请求

func (*Session) Put

func (s *Session) Put(urlStr string, options *HttpHeader) (*http.Request, *Response, error)

Put 使用put请求

func (*Session) Request

func (s *Session) Request(method string, urlStr string, options *HttpHeader) (*http.Request, *Response, error)

func (*Session) ResetRequestHooks

func (s *Session) ResetRequestHooks()

ResetRequestHooks 重置请求钩子函数

func (*Session) ResetResponseHooks

func (s *Session) ResetResponseHooks()

ResetResponseHooks 重置响应钩子函数

Jump to

Keyboard shortcuts

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