netutil

package
v0.0.0-...-15c4667 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileDownload

func FileDownload(url, filePath string) error

FileDownload 文件下载

Params:

url: 文件地址
filePath: 文件路径

func FileDownloadWithProgress

func FileDownloadWithProgress(url string, filePath string, callback DownloadProgressCallback) error

FileDownloadWithProgress 带进度的文件下载

Params:

url: 文件地址
filePath: 文件路径
callback: 用于通知下载进度

func HttpDelete

func HttpDelete(url string, header ...byte) ([]byte, error)

HttpDelete http delete 请求

Params:

url: 请求地址
header: 请求头

func HttpDeleteWithTimeout

func HttpDeleteWithTimeout(url string, timeout time.Duration, header ...byte) ([]byte, error)

HttpDeleteWithTimeout http delete 请求带超时时长

Params:

url: 请求地址
timeout: 超时时间
header: 请求头

func HttpGet

func HttpGet(url string, header ...byte) ([]byte, error)

HttpGet http get 请求

Params:

url: 请求地址
header: 请求头

func HttpGetWithTimeout

func HttpGetWithTimeout(url string, timeout time.Duration, header ...byte) ([]byte, error)

HttpGetWithTimeout http get 请求

Params:

url: 请求地址
timeout: 超时时间
header: 请求头

func HttpPost

func HttpPost(url string, data any, header ...byte) ([]byte, error)

HttpPost http post 请求

Params:

url: 请求地址
data: 请求参数
header: 请求头

func HttpPostWithTimeout

func HttpPostWithTimeout(url string, data any, timeout time.Duration, header ...byte) ([]byte, error)

HttpPostWithTimeout http post 请求

Params:

url: 请求地址
data: 请求参数
timeout: 超时时间
header: 请求头

func HttpPut

func HttpPut(url string, data any, header ...byte) ([]byte, error)

HttpPut http put 请求

Params:

url: 请求地址
data: 请求参数
header: 请求头

func HttpPutWithTimeout

func HttpPutWithTimeout(url string, data any, timeout time.Duration, header ...byte) ([]byte, error)

HttpPutWithTimeout http put 请求

Params:

url: 请求地址
data: 请求参数
timeout: 超时时间
header: 请求头

func Ipv4sLocal

func Ipv4sLocal() ([]string, error)

Ipv4sLocal 获取本地ipv4地址

func ParseResponse

func ParseResponse[T any](respBytes []byte, err error) (T, error)

ParseResponse 解析响应

Params:

T: 为返回值类型
respBytes: 响应字节数组
err: httpRequest 错误

func ShouldBindJson

func ShouldBindJson(req *http.Request, data any) error

ShouldBindJson json入参绑定

Params:

req: 请求对象
data: 待绑定数据结构体指针

func ShouldBindQuery

func ShouldBindQuery(req *http.Request, data any) error

ShouldBindQuery query入参绑定

Params:

req: 请求对象
data: 待绑定数据结构体指针

func UrlBase

func UrlBase(rawURL string) string

UrlBase 获取URL路径的基础名称

Params:

rawURL: 资源的网络地址

Examples:

UrlBase("https://example.com/path/to/file.txt") // file.txt

Types

type DownloadProgress

type DownloadProgress struct {
	Total  int64 // 文件总大小
	Finish int64 // 当前已写入大小
	// contains filtered or unexported fields
}

DownloadProgress 包装了一个 io.Writer,并加入了进度回调功能。

func FileDownloadWithNotify

func FileDownloadWithNotify(ch chan DownloadProgress, url, filePath string) (*DownloadProgress, error)

FileDownloadWithNotify 带通知的文件下载

Params:

ch: 通知进度
url: 文件地址
filePath: 文件路径

func (*DownloadProgress) Write

func (pw *DownloadProgress) Write(p []byte) (int, error)

Write 实现了 io.Writer 接口。 每次有数据块写入时,这个方法会被调用。

type DownloadProgressCallback

type DownloadProgressCallback func(finishBytes, totalBytes int64)

type Mail

type Mail struct {
	Username string // 用户名
	Password string // 密码
	Addr     string // smtp地址, 例如 mail.example.com:smtp
	From     string // 发送者
}

func (Mail) SendMail

func (mail Mail) SendMail(receiveUsers []string, subject, content string) error

SendMail 发送邮件

Params:

receiveUsers: 接收者
subject: 主题
content: 正文

Jump to

Keyboard shortcuts

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