Documentation
¶
Index ¶
- Variables
- func AppendFile(path string, data []byte) error
- func Base64Decode(s string) ([]byte, error)
- func Base64Encode(data []byte) string
- func Base64URLDecode(s string) ([]byte, error)
- func Base64URLEncode(data []byte) string
- func CalcOffset(page, pageSize int) int
- func CalcPageCount(total, pageSize int64) int64
- func CopyFile(dst, src string) error
- func DefaultIfBlank(s, def string) string
- func DirExists(path string) bool
- func EndOfDay(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EnsureDir(path string) error
- func EqualsIgnoreCase(a, b string) bool
- func FileExists(path string) bool
- func FileSize(path string) (int64, error)
- func FormatDate(t time.Time) string
- func FormatDateTime(t time.Time) string
- func FormatTime(t time.Time, layout string) string
- func FormatTimeOnly(t time.Time) string
- func FromTimestamp(timestamp int64) time.Time
- func FromUnix(unix int64) time.Time
- func GetDateInt(t time.Time) int
- func HTTPGet(url string, params map[string]string) ([]byte, error)
- func HTTPPost(url string, params map[string]string) ([]byte, error)
- func HTTPPostJSON(url string, data any) ([]byte, error)
- func HasChinese(s string) bool
- func HashFile(path string, newHash func() hash.Hash) (string, error)
- func IsAllBlank(strs ...string) bool
- func IsAlpha(s string) bool
- func IsAlphanumeric(s string) bool
- func IsAnyBlank(strs ...string) bool
- func IsBlank(s string) bool
- func IsChinese(s string) bool
- func IsEmail(email string) bool
- func IsEmpty(v any) bool
- func IsIDCard(id string) bool
- func IsIPv4(ip string) bool
- func IsNotBlank(s string) bool
- func IsNumeric(s string) bool
- func IsPhone(phone string) bool
- func JSONMarshal(v any) ([]byte, error)
- func MD5(s string) string
- func MD5Bytes(data []byte) string
- func Nl2br(s string, isXhtml bool) string
- func NowTimestamp() int64
- func NowUnix() int64
- func ParseDateInt(date int) time.Time
- func ParseTime(timeStr, layout string) (time.Time, error)
- func RandDigit(n int) string
- func RandInt(min, max int) int
- func RandInt64(min, max int64) int64
- func RandString(n int) string
- func ReadFile(path string) ([]byte, error)
- func RemoveFile(path string) error
- func SHA1(s string) string
- func SHA256(s string) string
- func SHA256Bytes(data []byte) string
- func StartOfDay(t time.Time) time.Time
- func StartOfMonth(t time.Time) time.Time
- func StartOfWeek(t time.Time) time.Time
- func StrLen(s string) int
- func Substr(s string, start, length int) string
- func ToFloat64(s string) float64
- func ToFloat64Default(s string, def float64) float64
- func ToInt(s string) int
- func ToInt64(s string) int64
- func ToInt64Default(s string, def int64) int64
- func ToIntDefault(s string, def int) int
- func ToString(n int) string
- func ToString64(n int64) string
- func ToUint64(s string) uint64
- func ToUint64Default(s string, def uint64) uint64
- func Trim(s string) string
- func URLDecode(s string) (string, error)
- func URLEncode(s string) string
- func UUID() string
- func UUIDParse(s string) (uuid.UUID, error)
- func UUIDShort() string
- func UUIDValid(s string) bool
- func WriteFile(path string, data []byte) error
- type HTTPClient
- func (c *HTTPClient) Close()
- func (c *HTTPClient) Delete(urlStr string) ([]byte, error)
- func (c *HTTPClient) DoWithResponse(req *http.Request) (*http.Response, error)
- func (c *HTTPClient) Get(urlStr string, params map[string]string) ([]byte, error)
- func (c *HTTPClient) Post(urlStr string, params map[string]string) ([]byte, error)
- func (c *HTTPClient) PostJSON(urlStr string, data any) ([]byte, error)
- func (c *HTTPClient) Put(urlStr string, data any) ([]byte, error)
- func (c *HTTPClient) Request(method, urlStr string, body []byte) ([]byte, error)
- func (c *HTTPClient) SetCookie(key, value string) *HTTPClient
- func (c *HTTPClient) SetHeader(key, value string) *HTTPClient
- func (c *HTTPClient) SetHeaders(headers map[string]string) *HTTPClient
- func (c *HTTPClient) SetSkipTLS(skip bool) *HTTPClient
- func (c *HTTPClient) SetTimeout(timeout time.Duration) *HTTPClient
- func (c *HTTPClient) Upload(urlStr string, files []UploadFile, params map[string]string) ([]byte, error)
- func (c *HTTPClient) UploadFromBytes(urlStr string, fieldName string, filename string, data []byte, ...) ([]byte, error)
- type HTTPClientConfig
- type URLBuilder
- func (b *URLBuilder) AddQueries(params map[string]string) *URLBuilder
- func (b *URLBuilder) AddQuery(key, value string) *URLBuilder
- func (b *URLBuilder) Build() *url.URL
- func (b *URLBuilder) SetHost(host string) *URLBuilder
- func (b *URLBuilder) SetPath(path string) *URLBuilder
- func (b *URLBuilder) SetQuery(key, value string) *URLBuilder
- func (b *URLBuilder) SetScheme(scheme string) *URLBuilder
- func (b *URLBuilder) String() string
- type UploadFile
Constants ¶
This section is empty.
Variables ¶
var DefaultHTTPClientConfig = HTTPClientConfig{ Timeout: 30 * time.Second, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, MaxConnsPerHost: 10, MaxIdleConnsPerHost: 10, SkipTLSVerify: true, }
DefaultHTTPClientConfig 默认配置
Functions ¶
func Base64URLDecode ¶
Base64URLDecode URL 安全的 Base64 解码
func FormatDateTime ¶
FormatDateTime 格式化为标准日期时间 "2006-01-02 15:04:05"
func HTTPPostJSON ¶
HTTPPostJSON 使用默认客户端发送 JSON POST 请求
func ToFloat64Default ¶
ToFloat64Default 字符串转 float64,失败返回默认值
func ToInt64Default ¶
ToInt64Default 字符串转 int64,失败返回默认值
func ToUint64Default ¶
ToUint64Default 字符串转 uint64,失败返回默认值
Types ¶
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient HTTP 客户端封装
func NewHTTPClientWithConfig ¶
func NewHTTPClientWithConfig(cfg HTTPClientConfig) *HTTPClient
NewHTTPClientWithConfig 使用自定义配置创建 HTTP 客户端
func (*HTTPClient) Delete ¶
func (c *HTTPClient) Delete(urlStr string) ([]byte, error)
Delete 发送 DELETE 请求
func (*HTTPClient) DoWithResponse ¶
DoWithResponse 执行请求并返回完整响应
func (*HTTPClient) PostJSON ¶
func (c *HTTPClient) PostJSON(urlStr string, data any) ([]byte, error)
PostJSON 发送 POST 请求(JSON 格式)
func (*HTTPClient) Put ¶
func (c *HTTPClient) Put(urlStr string, data any) ([]byte, error)
Put 发送 PUT 请求(JSON 格式)
func (*HTTPClient) Request ¶
func (c *HTTPClient) Request(method, urlStr string, body []byte) ([]byte, error)
Request 发送自定义请求
func (*HTTPClient) SetCookie ¶
func (c *HTTPClient) SetCookie(key, value string) *HTTPClient
SetCookie 设置 Cookie
func (*HTTPClient) SetHeader ¶
func (c *HTTPClient) SetHeader(key, value string) *HTTPClient
SetHeader 设置请求头
func (*HTTPClient) SetHeaders ¶
func (c *HTTPClient) SetHeaders(headers map[string]string) *HTTPClient
SetHeaders 批量设置请求头
func (*HTTPClient) SetSkipTLS ¶
func (c *HTTPClient) SetSkipTLS(skip bool) *HTTPClient
SetSkipTLS 设置是否跳过 TLS 验证 注意: 修改 TLS 配置需要重新创建 Transport
func (*HTTPClient) SetTimeout ¶
func (c *HTTPClient) SetTimeout(timeout time.Duration) *HTTPClient
SetTimeout 设置超时时间
func (*HTTPClient) Upload ¶
func (c *HTTPClient) Upload(urlStr string, files []UploadFile, params map[string]string) ([]byte, error)
Upload 上传文件
type HTTPClientConfig ¶
type HTTPClientConfig struct {
Timeout time.Duration // 请求超时时间
MaxIdleConns int // 最大空闲连接数
IdleConnTimeout time.Duration // 空闲连接超时时间
MaxConnsPerHost int // 每个主机最大连接数
MaxIdleConnsPerHost int // 每个主机最大空闲连接数
SkipTLSVerify bool // 是否跳过 TLS 验证
}
HTTPClientConfig HTTP 客户端配置
type URLBuilder ¶
type URLBuilder struct {
// contains filtered or unexported fields
}
URLBuilder URL 构建器
func (*URLBuilder) AddQueries ¶
func (b *URLBuilder) AddQueries(params map[string]string) *URLBuilder
AddQueries 批量添加查询参数
func (*URLBuilder) AddQuery ¶
func (b *URLBuilder) AddQuery(key, value string) *URLBuilder
AddQuery 添加单个查询参数
func (*URLBuilder) SetQuery ¶
func (b *URLBuilder) SetQuery(key, value string) *URLBuilder
SetQuery 设置查询参数(覆盖同名参数)
func (*URLBuilder) SetScheme ¶
func (b *URLBuilder) SetScheme(scheme string) *URLBuilder
SetScheme 设置协议(http/https)
type UploadFile ¶
UploadFile 上传文件信息