Documentation
¶
Index ¶
- Constants
- Variables
- func Account(value string, min, max uint8) error
- func AddFileToTar(tarWriter *tar.Writer, fileToCompress string, baseDir string) error
- func AddFileToZip(zipWriter *zip.Writer, fileToCompress string, baseDir string) error
- func AddPEMHeaders(key, keyType string) (string, error)
- func AddTime(t time.Time, addTimes ...string) (time.Time, error)
- func After(layout string, t1, t2 string) (bool, error)
- func Alnum(value string) bool
- func Alpha(value string) bool
- func Amount(amount string, decimal uint8, signed ...bool) bool
- func Before(layout string, t1, t2 string) (bool, error)
- func BinDec(str string) (int64, error)
- func BinHex(str string) (string, error)
- func BinOct(str string) (string, error)
- func CST() *time.Location
- func Certificate(config *tls.Config, certFile, keyFile string) error
- func CheckDate(year, month, day int) bool
- func ClientIP(r *http.Request) string
- func Copy(src, dst string) error
- func Date(timeZone *time.Location, layout string, timestamp ...int64) string
- func DateInfo(t time.Time) map[string]interface{}
- func DecBin(number int64) string
- func DecHex(number int64) string
- func DecOct(number int64) string
- func Diff[T Ordered](s1, s2 []T) []T
- func Domain(value string) bool
- func DrainBody(b io.ReadCloser) ([]byte, io.ReadCloser, error)
- func Email(value string) bool
- func Empty(value string) bool
- func Equal(layout string, t1, t2 string) (bool, error)
- func FileType(f *os.File) (string, error)
- func GenerateKeyRSA(path string, bits int, pkcs ...bool) ([]string, error)
- func GetEnv(key string, defaultVal ...string) string
- func GetRandPool() *rand.Rand
- func HasCount[T Ordered](v T, s []T) (count int)
- func HasSymbols(value string) bool
- func HexBin(data string) (string, error)
- func HexDec(str string) (int64, error)
- func HexOct(str string) (string, error)
- func Intersect[T Ordered](s1, s2 []T) []T
- func IsDir(path string) bool
- func IsExist(path string) bool
- func IsFile(filepath string) bool
- func IsHas[T Ordered](v T, s []T) bool
- func Line(r io.Reader, handle ReadLine) error
- func Local() *time.Location
- func LocalIP() string
- func LogArgsFormat(args []any) string
- func MapDiff[K, V Ordered](m1, m2 map[K]V) []V
- func MapDiffKey[K Ordered, V any](m1, m2 map[K]V) []K
- func MapFilter[K Ordered, V any](m map[K]V, f func(key K, value V) bool) map[K]V
- func MapIntersect[K, V Ordered](m1, m2 map[K]V) []V
- func MapIntersectKey[K Ordered, V any](m1, m2 map[K]V) []K
- func MapKeys[K Ordered, V any](m map[K]V) []K
- func MapRange[K Ordered, V any](m map[K]V, f func(key K, value V) bool, isReverse ...bool)
- func MapValues[K Ordered, V any](m map[K]V, isReverse ...bool) []V
- func Marshal(v any) ([]byte, error)
- func Md5(str string) string
- func MixStr(value string) bool
- func Mobile(value string) bool
- func MonthDay(year int, month int) (days int)
- func NumberFormat(number float64, decimals uint, decPoint, thousandsSep string) string
- func Numeric(value string) bool
- func OctBin(data string) (string, error)
- func OctDec(str string) (int64, error)
- func OctHex(data string) (string, error)
- func PassWord(value string, min, max uint8) error
- func PassWord2(value string, min, max uint8) error
- func PassWord3(value string, min, max uint8) error
- func Phone(value string) bool
- func Pkcs7Padding(data []byte, blockSize int) []byte
- func Pkcs7UnPadding(data []byte) ([]byte, error)
- func ProxyURL(transport *http.Transport, proxyURL string) error
- func QQ(value string) bool
- func Rand(minInt, maxInt int64, r ...*rand.Rand) int64
- func RandStr(n int, r ...*rand.Rand) string
- func RandStr2(n int, r ...*rand.Rand) string
- func RandStr3(n int, alpha string, r ...*rand.Rand) string
- func Read(r io.Reader, handle ReadBlock) error
- func Redirect(w http.ResponseWriter, url string, statusCode ...int)
- func RemovePEMHeaders(pem string) string
- func Replace(s string, oldnew map[string]string) string
- func Reverse[T Ordered](s []T) []T
- func RootCAs(config *tls.Config, rootCAs string) error
- func Round(num float64, precision int) float64
- func Scan(r io.Reader, handle ReadScan, size ...int) error
- func ServerIP() string
- func SetJsonMethod(encode func(v any) ([]byte, error), decode func(data []byte, v any) error)
- func Sha1(str string) string
- func Sha256(str string) string
- func Sha512(str string) string
- func Size(filepath string) (int64, error)
- func SizeFormat(size int64, decimals uint) string
- func Str2Float(s string) (i float64)
- func Str2Int(s string) (i int)
- func Str2Int64(s string) (i int64)
- func StrRev(str string) string
- func Strtotime(timeZone *time.Location, parse ...string) (t time.Time, err error)
- func Sub(layout string, t1, t2 string) (time.Duration, error)
- func Substr(str string, start, length int) string
- func Tar(tarFile string, files []string) error
- func TarGz(tarGzFile string, files []string) error
- func Ternary[T any](expr bool, trueVal, falseVal T) T
- func TimeDay(value string) bool
- func TimeFormat(timeZone *time.Location, layout string, timestamp ...int64) string
- func TimeMonth(value string) bool
- func TimeParse(timeZone *time.Location, layout, timeStr string) (time.Time, error)
- func Timestamp(value string) bool
- func UTC() *time.Location
- func UnIntZero(value string) bool
- func UnInteger(value string) bool
- func UnNumeric(value string) bool
- func UnTar(tarFile, destDir string) error
- func UnZip(zipFile, destDir string) error
- func UniqId(l uint8, r ...*rand.Rand) string
- func Unique[T Ordered](s []T) []T
- func Unmarshal(data []byte, v any) error
- func UrlPath(urlPath string, params url.Values) (string, error)
- func ZeroPadding(data []byte, blockSize int) []byte
- func ZeroUnPadding(data []byte) ([]byte, error)
- func Zh(value string) bool
- func Zip(zipFile string, files []string) error
- type Body
- type Cipher
- func (c *Cipher) Check() error
- func (c *Cipher) Decrypt(encrypt string, mode McryptMode, decode Decode, unPadding UnPadding) (string, error)
- func (c *Cipher) DecryptCBC(data []byte, unPadding UnPadding) ([]byte, error)
- func (c *Cipher) DecryptCFB(data []byte, unPadding UnPadding) ([]byte, error)
- func (c *Cipher) DecryptCTR(data []byte, unPadding UnPadding) ([]byte, error)
- func (c *Cipher) DecryptECB(data []byte, unPadding UnPadding) ([]byte, error)
- func (c *Cipher) DecryptOFB(data []byte, unPadding UnPadding) ([]byte, error)
- func (c *Cipher) Encrypt(data string, mode McryptMode, encode Encode, padding Padding) (string, error)
- func (c *Cipher) EncryptCBC(data []byte, padding Padding) ([]byte, error)
- func (c *Cipher) EncryptCFB(data []byte, padding Padding) ([]byte, error)
- func (c *Cipher) EncryptCTR(data []byte, padding Padding) ([]byte, error)
- func (c *Cipher) EncryptECB(data []byte, padding Padding) ([]byte, error)
- func (c *Cipher) EncryptOFB(data []byte, padding Padding) ([]byte, error)
- func (c *Cipher) IsSetKey() bool
- func (c *Cipher) SetIv(iv string) error
- func (c *Cipher) SetKey(key string, block CipherBlock) (err error)
- type CipherBlock
- type Curl
- func (c *Curl) AddCookies(cookies ...*http.Cookie) *Curl
- func (c *Curl) AddHeader(key string, values ...string) *Curl
- func (c *Curl) AddHeaders(Headers map[string][]string) *Curl
- func (c *Curl) AddParam(key string, values ...string) *Curl
- func (c *Curl) AddParams(params map[string][]string) *Curl
- func (c *Curl) ClearCookies()
- func (c *Curl) Client(f func(request *http.Client) error) *Curl
- func (c *Curl) CloseIdleConnections()
- func (c *Curl) DelCookies(cookieName ...string)
- func (c *Curl) DelHeaders(keys ...string)
- func (c *Curl) DelParams(keys ...string)
- func (c *Curl) Delete(url string) (err error)
- func (c *Curl) Done(f func(client *http.Client, request *http.Request, response *http.Response)) *Curl
- func (c *Curl) Get(url string) (err error)
- func (c *Curl) GetCookie(cookieName string) *http.Cookie
- func (c *Curl) GetHeader() http.Header
- func (c *Curl) GetHeaderValues(key string) []string
- func (c *Curl) GetParamValues(key string) []string
- func (c *Curl) GetParams() url.Values
- func (c *Curl) GetRequestId() string
- func (c *Curl) HasCookie(cookieName string) bool
- func (c *Curl) HasHeader(key string) bool
- func (c *Curl) HasParam(key string) bool
- func (c *Curl) Head(url string) error
- func (c *Curl) InsecureSkipVerify(isSkip bool) *Curl
- func (c *Curl) Options(url string) (err error)
- func (c *Curl) Patch(url string) (err error)
- func (c *Curl) Post(url string) (err error)
- func (c *Curl) PostForm(url string) error
- func (c *Curl) Put(url string) (err error)
- func (c *Curl) ReSetHeader(header http.Header) *Curl
- func (c *Curl) ReSetParams(params url.Values) *Curl
- func (c *Curl) Request(f func(request *http.Request) error) *Curl
- func (c *Curl) Resolve(f func(body []byte) error) *Curl
- func (c *Curl) Response(f func(response *http.Response) (isDone bool, err error)) *Curl
- func (c *Curl) Send(method, url string, body io.Reader) (err error)
- func (c *Curl) SetBasicAuth(username, password string) *Curl
- func (c *Curl) SetBody(body io.Reader) *Curl
- func (c *Curl) SetBodyBytes(body []byte) *Curl
- func (c *Curl) SetCertKey(cert, key string) *Curl
- func (c *Curl) SetContentType(contentType string) *Curl
- func (c *Curl) SetCookies(cookies ...*http.Cookie) *Curl
- func (c *Curl) SetDefLogOutput(enable bool) *Curl
- func (c *Curl) SetDump(dump bool) *Curl
- func (c *Curl) SetHeader(key, value string) *Curl
- func (c *Curl) SetHeaders(headers map[string]string) *Curl
- func (c *Curl) SetMaxRetry(max uint8) *Curl
- func (c *Curl) SetParam(key, value string) *Curl
- func (c *Curl) SetParams(params map[string]string) *Curl
- func (c *Curl) SetProxyURL(proxyURL string) *Curl
- func (c *Curl) SetRequestId(requestId ...string) *Curl
- func (c *Curl) SetRootCAs(rootCAs string) *Curl
- func (c *Curl) SetStatusCode(statusCode ...int) *Curl
- func (c *Curl) SetTimeout(timeout uint8) *Curl
- func (c *Curl) SetUserAgent(userAgent string) *Curl
- type Decode
- type Encode
- type FileInfo
- type Float
- type Form
- func (f *Form) AddFile(fileName string, filePath ...string) *Form
- func (f *Form) AddFiles(files map[string][]string) *Form
- func (f *Form) AddParam(key string, values ...string) *Form
- func (f *Form) AddParams(params map[string][]string) *Form
- func (f *Form) DelFiles(fileNames ...string)
- func (f *Form) DelParams(keys ...string)
- func (f *Form) Reader() (body io.Reader, contentType string, err error)
- func (f *Form) SetFile(fileName, filePath string) *Form
- func (f *Form) SetFiles(files map[string]string) *Form
- func (f *Form) SetParam(key, value string) *Form
- func (f *Form) SetParams(params map[string]string) *Form
- type Frame
- type Integer
- type McryptMode
- type Number
- type Ordered
- type Padding
- type RSA
- func (r *RSA) Decrypt(encrypt string, decode Decode) (string, error)
- func (r *RSA) DecryptOAEP(encrypt string, decode Decode, hash hash.Hash) (string, error)
- func (r *RSA) Encrypt(data string, encode Encode) (string, error)
- func (r *RSA) EncryptOAEP(data string, encode Encode, hash hash.Hash) (string, error)
- func (r *RSA) IsSetPrivateKey() error
- func (r *RSA) IsSetPublicKey() error
- func (r *RSA) SetPrivateKey(privateKey string, isFilePath ...bool) error
- func (r *RSA) SetPublicKey(publicKey string, isFilePath ...bool) error
- func (r *RSA) Sign(data string, hash crypto.Hash, encode Encode) (string, error)
- func (r *RSA) SignPSS(data string, hash crypto.Hash, encode Encode, opts *rsa.PSSOptions) (string, error)
- func (r *RSA) Verify(data, sign string, hash crypto.Hash, decode Decode) error
- func (r *RSA) VerifyPSS(data, sign string, hash crypto.Hash, decode Decode, opts *rsa.PSSOptions) error
- type ReadBlock
- type ReadLine
- type ReadScan
- type Response
- func (r *Response[T]) ContentType(contentType string) *Response[T]
- func (r *Response[T]) Download(filePath string, rename ...string)
- func (r *Response[T]) Encode() ([]byte, error)
- func (r *Response[T]) Fail(code int, message string, data ...T)
- func (r *Response[T]) Herder(f func(header http.Header)) *Response[T]
- func (r *Response[T]) Html(data string)
- func (r *Response[T]) Show(filePath string)
- func (r *Response[T]) StatusCode(statusCode int) *Response[T]
- func (r *Response[T]) Success(code int, data T, message ...string)
- func (r *Response[T]) Text(data string)
- func (r *Response[T]) Write(body []byte)
- func (r *Response[T]) Xml(data any)
- type Signed
- type Slice
- type UnPadding
- type Unsigned
- type WriteFile
Examples ¶
Constants ¶
const ( Byte int64 = 1 << (10 * iota) // 1Byte KB // 1024Byte = 1KB MB // 1048576Byte = 1024KB = 1MB GB // 1073741824Byte = 1048576KB = 1024MB = 1GB TB // 1099511627776Byte = ... PB // 1125899906842624Byte EB // 1152921504606846976Byte )
计算机存储单位:Byte、KB、MB、GB、TB、PB、EB int64最大支持EB
const ( Year string = "2006" // 年 Month string = "01" // 月 Day string = "02" // 日 Hour string = "15" // 时 Minute string = "04" // 分 Second string = "05" // 秒 DateMonth = Year + "-" + Month // 2006-01 DateHour = time.DateOnly + " " + Hour // 2006-01-02 15 DateMinute = DateHour + ":" + Minute // 2006-01-02 15:04 DateMillisecond = time.DateTime + ".000" // 2006-01-02 15:04:05.000 DateMicrosecond = DateMillisecond + "000" // 2006-01-02 15:04:05.000000 DateNanosecond = DateMicrosecond + "000" // 2006-01-02 15:04:05.000000000 MonthSeam = Year + Month // 200601 DaySeam = MonthSeam + Day // 20060102 HourSeam = DaySeam + Hour // 2006010215 MinuteSeam = HourSeam + Minute // 200601021504 SecondSeam = MinuteSeam + Second // 20060102150405 )
时间格式化格式
const ( // ALPHA 英文字母:A-Za-z ALPHA = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz` // DIGIT 数字:0-9 DIGIT = `0123456789` // ALNUM 英文字母+数字:A-Za-z0-9 ALNUM = ALPHA + DIGIT )
Variables ¶
var DONE = errors.New("DONE")
DONE 完成终止
var RandPool = &sync.Pool{New: func() interface{} { return rand.New(rand.NewPCG(uint64(time.Now().UnixNano()), uint64(time.Now().UnixNano()))) }}
RandPool rand
Functions ¶
func AddTime ¶ added in v1.21.4
AddTime 增加时间
addTimes 增加时间(Y年,M月,D日,H时,I分,S秒,L毫秒,C微妙,N纳秒) 示例:DateInfo(time, "-1D", "1M", "-1Y", "+4H", "20I", "30S", "76N")
func Date ¶
Date 使用 patterns 定义的格式对时间格式化
timeZone 时区 layout 格式化,例: - Date(timeZone, "Y-m-d H:i:s", unix) timestamp Unix时间戳:sec秒和nsec纳秒
func DateInfo ¶
DateInfo 获取日期信息
返回:year int - 年, month int - 月,monthEn string - 英文月, day int - 日,yearDay int - 一年中第几日, weekDay int - 一周中第几日, hour int - 时,hour int - 分,second int - 秒, millisecond int - 毫秒,microsecond int - 微妙,nanosecond int - 纳秒, unix int64 - 时间戳-秒,unixNano int64 - 时间戳-纳秒, weekDay int - 星期几,weekDayEn string - 星期几英文, yearWeek int - 一年中第几周, date string - 格式化日期,dateNs string - 格式化日期(纳秒)
func DrainBody ¶
func DrainBody(b io.ReadCloser) ([]byte, io.ReadCloser, error)
DrainBody 读取read内容并返回其内容和一个新的ReadCloser,
func GenerateKeyRSA ¶
GenerateKeyRSA 生成秘钥(公钥PKCS8格式 私钥PKCS1格式)
path 秘钥存放地址 bits 生成秘钥位大小: 512、1024、2048、4096 pkcs 秘钥格式, 默认格式(公钥PKCS8格式 私钥PKCS1格式): - pkcs[0] isPubPKCS8 公钥是否是PKCS8格式: 默认 true - pkcs[1] isPriPKCS1 私钥是否是PKCS1格式: 默认 true RETURN: - []string 返回两个文件名, 第一个公钥文件名, 第二个私钥文件名
func LogArgsFormat ¶ added in v1.21.0
LogArgsFormat 根据参数生成Format
func MapIntersectKey ¶
MapIntersectKey 计算m1与m2的键交集
func MapRange ¶
MapRange 有序遍历map元素,对map的key排序并按排序后的key遍历m
f 函数接收key与value,返回一个bool值,如果f函数返回false则终止遍历 isReverse 是否降序排列:true 降序,false 升序
func MapValues ¶
MapValues 有序获取map的所有value,对map的key排序并按排序后的key返回其value
isReverse 是否降序排列:true 降序,false 升序
func NumberFormat ¶
NumberFormat 以千位分隔符方式格式化一个数字
number 要格式化的数字 decimals 保留几位小数 decPoint 小数点[.] thousandsSep 千位分隔符[,]
func Rand ¶
Rand 返回min~max之间的随机数,值可能包含min和max
minInt 最小值 maxInt 最大值 r 随机种子 rand.NewSource(time.Now().UnixNano()) : 批量生成时传入r参数可提升生成随机数效率
func RandStr ¶
RandStr 随机生成字符串,使用LETTERS规则
n 生成字符串长度 r 随机种子 rand.NewSource(time.Now().UnixNano()) : 批量生成时传入r参数可提升生成随机数效率
func RandStr2 ¶
RandStr2 随机生成字符串,使用ALPHANUM规则
n 生成字符串长度 r 随机种子 rand.NewSource(time.Now().UnixNano()) : 批量生成时传入r参数可提升生成随机数效率
func RandStr3 ¶
RandStr3 随机生成字符串
n 生成字符串长度 alpha 生成随机字符串的种子 r 随机种子 rand.NewSource(time.Now().UnixNano()) : 批量生成时传入r参数可提升生成随机数效率
func Redirect ¶
func Redirect(w http.ResponseWriter, url string, statusCode ...int)
Redirect 重定向
url 重定向地址 statusCode 响应状态码:默认响应 302
Example ¶
serveMux.HandleFunc("/response/redirect", func(w http.ResponseWriter, r *http.Request) { // 重定向 utils.Redirect(w, "/response/json") })
Output:
func SetJsonMethod ¶
SetJsonMethod 设置json编码解码方法(三方开源库), 若未设置则默认使用encoding/json(标准库)。只需在程序入口处设置一次
func Strtotime ¶
Strtotime 解析时间字符串(不确定的时间格式,尽可能解析时间字符串)
timeZone 时区 parse 解析时间字符串包含两个参数: - layout 格式化样式字符串 - timeStr 时间字符串 例: - Strtotime(timeZone, "2006-01-02 15:04:05") // 当前时间 - Strtotime(timeZone, "2006-01-02 15:04:05", timeStr) // 指定时间timeStr - Strtotime(timeZone, "Y-m-d H:i:s") // 当前时间 - Strtotime(timeZone, "Y-m-d H:i:s", timeStr) // 指定时间timeStr
func Substr ¶
Substr 字符串截取
str 被截取的字符串 start 截取的起始位置,即截取的第一个字符所在的索引: - start小于0时,start = len(str) + start length 截取的截止位置,即截取的最后一个字符所在的索引: - length大于0时,length表示为截取子字符串的长度,截取的最后一个字符所在的索引值为:start + length - length小于0时,length表示为截取的最后一个字符所在的索引,值为:len(str) + length + 1 - 例如:等于-1时,表示截取到最后一个字符;等于-2时,表示截取到倒数第二个字符
func TimeFormat ¶
TimeFormat 时间戳格式化为时间字符串
timeZone 时区 layout 格式化,例: - TimeFormat(timeZone, "2006-01-02 15:04:05", unix) timestamp Unix时间戳:sec秒和nsec纳秒
func TimeParse ¶
TimeParse 解析时间字符串
timeZone 时区 layout 格式化,例: - TimeFormat(timeZone, "2006-01-02 15:04:05", timeStr) timeStr 时间字符串
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
func NewCipher ¶
func NewCipher(key string, block CipherBlock, isRandIV bool) (*Cipher, error)
NewCipher Cipher
key 秘钥 block 密码: (AES | DES).NewCipher isRandIV 随机生成IV: true 随机生成的IV会在加密后的密文开头
func (*Cipher) Decrypt ¶
func (c *Cipher) Decrypt(encrypt string, mode McryptMode, decode Decode, unPadding UnPadding) (string, error)
Decrypt 加密
encrypt 待解密数据 mode 加密模式: - ECB: Decrypt(encrypt, ECB, decode, unPadding) - CBC: Decrypt(encrypt, CBC, decode, unPadding) - CTR: Decrypt(encrypt, CTR, decode, unPadding) - CFB: Decrypt(encrypt, CFB, decode, unPadding) - OFB: Decrypt(encrypt, OFB, decode, unPadding) decode 解码方法 unPadding 去除填充数据方法
func (*Cipher) DecryptCBC ¶
DecryptCBC 解密
func (*Cipher) DecryptCFB ¶
DecryptCFB 解密
func (*Cipher) DecryptCTR ¶
DecryptCTR 解密
func (*Cipher) DecryptECB ¶
DecryptECB 解密
func (*Cipher) DecryptOFB ¶
DecryptOFB 解密
func (*Cipher) Encrypt ¶
func (c *Cipher) Encrypt(data string, mode McryptMode, encode Encode, padding Padding) (string, error)
Encrypt 加密
data 待加密数据 mode 加密模式: - ECB: Encrypt(data, ECB, encode, padding) - CBC: Encrypt(data, CBC, encode, padding) - CTR: Encrypt(data, CTR, encode, padding) - CFB: Encrypt(data, CFB, encode, padding) - OFB: Encrypt(data, OFB, encode, padding) encode 编码方法 padding 填充数据方法
func (*Cipher) EncryptCBC ¶
EncryptCBC 加密
func (*Cipher) EncryptCFB ¶
EncryptCFB 加密
func (*Cipher) EncryptCTR ¶
EncryptCTR 加密
func (*Cipher) EncryptECB ¶
EncryptECB 加密
func (*Cipher) EncryptOFB ¶
EncryptOFB 加密
type Curl ¶
func (*Curl) AddCookies ¶
AddCookies 设置cookies
func (*Curl) AddHeaders ¶
AddHeaders 对header键添加多个值
func (*Curl) Done ¶
func (c *Curl) Done(f func(client *http.Client, request *http.Request, response *http.Response)) *Curl
Done 请求完成后的处理方法, 如关闭连接等操作。 注意:client、request、response 有可能为nil
func (*Curl) GetHeaderValues ¶
GetHeaderValues 获取header内指定键的值
func (*Curl) GetParamValues ¶
GetParamValues 获取params指定键的值
func (*Curl) InsecureSkipVerify ¶
InsecureSkipVerify 设置是否跳过https不安全验证
func (*Curl) ReSetHeader ¶
ReSetHeader 重置header
func (*Curl) Response ¶
Response 在发送请求之后可以对Response处理方法
isDone 返回true 终止调用该方法之后的代码; 返回false 继续执行后续代码
func (*Curl) SetBasicAuth ¶
SetBasicAuth 设置Basic认证的账号及密码
func (*Curl) SetContentType ¶
SetContentType 设置请求头 Content-Type
contentType 类型:"application/x-www-form-urlencoded", "application/json", "multipart/form-data", "text/plain"
func (*Curl) SetCookies ¶
SetCookies 设置cookies
func (*Curl) SetDefLogOutput ¶ added in v1.21.0
SetDefLogOutput 打印默认日志(INFO及以下级别日志: true 打印, false 禁止打印
func (*Curl) SetHeaders ¶
SetHeaders 设置header键值对
func (*Curl) SetMaxRetry ¶ added in v1.21.0
SetMaxRetry 设置失败重连次数
func (*Curl) SetRequestId ¶
SetRequestId 设置RequestId
func (*Curl) SetStatusCode ¶
SetStatusCode 设置返回状态码,除200以外需特殊处理的状态码
func (*Curl) SetUserAgent ¶
SetUserAgent 设置请求头 User-Agent
type FileInfo ¶
FileInfo 文件信息
func FindFiles ¶
FindFiles 获取目录下所有匹配文件
path 目录 depth 深度查找: true 采用filepath.WalkDir遍历; false 只在当前目录查找 match 匹配规则: - `无参` : 匹配所有文件名 FindFiles(path, depth) - `*` : 匹配所有文件名 FindFiles(path, depth, `*`) - `文件完整名` : 精准匹配文件名 FindFiles(path, depth, fullFileName) - `e`, `文件完整名` : 精准匹配文件名 FindFiles(path, depth, `e`, fullFileName) - `p`, `文件前缀名` : 匹配前缀文件名 FindFiles(path, depth, `p`, fileNamePrefix) - `s`, `文件后缀名` : 匹配后缀文件名 FindFiles(path, depth, `s`, fileNameSuffix) - `r`, `正则表达式` : 正则匹配文件名 FindFiles(path, depth, `r`, fileNameReg)
type Form ¶
Form 表单
type McryptMode ¶
type McryptMode int8
McryptMode 密码模式
const ( ECB McryptMode = iota // 0 电码本模式(Electronic Codebook Book,ECB),ECB无须设置初始化向量IV CBC // 1 密码分组链接模式(Cipher Block Chaining ,CBC),如果明文长度不是分组长度16字节(des 8字节)的整数倍需要进行填充 CTR // 2 计算器模式(Counter,CTR) CFB // 3 密码反馈模式(Cipher FeedBack,CFB) OFB // 4 输出反馈模式(Output FeedBack,OFB) )
加密模式
type RSA ¶
type RSA struct {
// contains filtered or unexported fields
}
func (*RSA) DecryptOAEP ¶ added in v1.21.5
DecryptOAEP 解密(私钥)
encrypt 代解密数据 decode 解码方法 hash OAEP编码方法
func (*RSA) IsSetPrivateKey ¶
IsSetPrivateKey 是否正确设置 PrivateKey
func (*RSA) Sign ¶
Sign 签名(私钥)
data 待签名数据 hash 加密哈希函数标识: - crypto.SHA256 : Sign(data, crypto.SHA256, encode) - crypto.MD5 : Sign(data, crypto.MD5, encode) encode - 编码方法
func (*RSA) SignPSS ¶ added in v1.21.5
func (r *RSA) SignPSS(data string, hash crypto.Hash, encode Encode, opts *rsa.PSSOptions) (string, error)
SignPSS 签名(私钥)
data 待签名数据 hash 加密哈希函数标识: - crypto.SHA256 : Sign(data, crypto.SHA256, encode) - crypto.MD5 : Sign(data, crypto.MD5, encode) encode - 编码方法 opts - *rsa.PSSOptions
func (*RSA) Verify ¶
Verify 验证签名(公钥)
data 待验证数据 sign 签名串 hash 加密哈希函数标识: - crypto.SHA256 : Verify(data, signature, crypto.SHA256, decode) - crypto.MD5 : Verify(data, signature, crypto.MD5, decode) decode 解码方法
func (*RSA) VerifyPSS ¶ added in v1.21.5
func (r *RSA) VerifyPSS(data, sign string, hash crypto.Hash, decode Decode, opts *rsa.PSSOptions) error
VerifyPSS 验证签名(公钥)
data 待验证数据 sign 签名串 hash 加密哈希函数标识: - crypto.SHA256 : Verify(data, signature, crypto.SHA256, decode) - crypto.MD5 : Verify(data, signature, crypto.MD5, decode) decode 解码方法
type ReadBlock ¶
ReadBlock 处理读取的数据块
- size 读取的数据块大小
- block 读取的数据块 返回值 - error 处理错误信息: 返回的 error == DONE 代表正确处理完数据并终止扫描
type ReadLine ¶
ReadLine 处理scan扫描的行数据
- num 行号: 当前扫描到第几行
- line 行数据: 当前扫描的行数据
- lineDone 当前行(num)数据是否读取完毕: true 当前行(num)数据读取完毕; false 当前行(num)数据未读完 返回值 - error 处理错误信息: 返回的 error == DONE 代表正确处理完数据并终止扫描
type ReadScan ¶
ReadScan 处理scan扫描的行数据
- num 行号: 当前扫描到第几行
- line 行数据: 当前扫描的行数据
- WrapError 扫描错误信息 返回值 - error 处理错误信息: 返回的 error == DONE 代表正确处理完数据并终止扫描
type Response ¶
func JsonResp ¶
func JsonResp[T any](w http.ResponseWriter, statusCode ...int) *Response[T]
JsonResp 响应Json数据
statusCode 响应状态码:默认响应 200
Example ¶
// 响应json数据 serveMux.HandleFunc("/response/json", func(w http.ResponseWriter, r *http.Request) { // 获取URL查询字符串参数 queryParam := r.URL.Query().Get("v") // 响应的数据 user := User{ Name: "张三", Age: 22, Sex: "男", IsMarried: false, Address: "北京市", phone: "131188889999", } if queryParam == "fail" { // 错误响应 utils.JsonResp[any](w, http.StatusNotAcceptable).Fail(20000, "fail") return } // 成功响应 utils.JsonResp[User](w).Success(10000, user) })
Output:
func View ¶
func View(w http.ResponseWriter, statusCode ...int) *Response[string]
View 响应文本视图
statusCode 响应状态码:默认响应 200
Example ¶
// 响应html serveMux.HandleFunc("/response/html", func(w http.ResponseWriter, r *http.Request) { // 响应html数据 utils.View(w).Html("<p>这是一个<b style=\"color: red\">段落!</b></p>") }) // 响应xml serveMux.HandleFunc("/response/xml", func(w http.ResponseWriter, r *http.Request) { // 响应的数据 user := User{ Name: "张三", Age: 22, Sex: "男", IsMarried: false, Address: "北京市", phone: "131188889999", } // 响应xml数据 utils.View(w).Xml(user) }) // 响应text serveMux.HandleFunc("/response/text", func(w http.ResponseWriter, r *http.Request) { // 响应text数据 utils.View(w).Text("<p>这是一个<b style=\"color: red\">段落!</b></p>") }) // 显示image serveMux.HandleFunc("/response/show", func(w http.ResponseWriter, r *http.Request) { // 获取URL查询字符串参数 file := r.URL.Query().Get("file") if utils.IsExist(file) { // 显示文件内容 utils.View(w).Show(file) return } // 处理错误 utils.View(w, http.StatusNotFound).Text("不存在的文件:" + file) }) // 下载文件 serveMux.HandleFunc("/response/download", func(w http.ResponseWriter, r *http.Request) { // 获取URL查询字符串参数 file := r.URL.Query().Get("file") if utils.IsExist(file) { // 下载文件数据 utils.View(w).Download(file) return } // 处理错误 utils.View(w, http.StatusNotFound).Text("不存在的文件:" + file) })
Output:
func (*Response[T]) ContentType ¶
ContentType 设置响应头 Content-Type
func (*Response[T]) StatusCode ¶
StatusCode 设置响应状态码,如:http.StatusOK