Documentation
¶
Index ¶
- Variables
- func AbsPath(skips ...int) string
- func AesDecrypt(baseStr string, key []byte) (origData []byte, aesErr error)
- func AesEncrypt(origData, key []byte) (string, error)
- func ArrayDifference[T interface{}](slices ...[]T) []T
- func ArrayIntersection[T interface{}](slices ...[]T) []T
- func ArrayUnion[T interface{}](slices ...[]T) []T
- func Base64Decode(s string) string
- func Base64Encode(s string) string
- func BasePath() string
- func BytesToString(b []byte) string
- func CBCDecrypt(sign string, key, iv []byte) (string, error)
- func CBCEncrypt(text string, key []byte, iv []byte) (string, error)
- func CapturePanic() (has bool)
- func CompareVersion(ver, cVer string) int
- func ConvertMoreTo[T any, T1 any](list []T, ty []T1) []T1
- func CopyFile(src, dst string) error
- func CopyMap[...](m map[T]T1) map[T]T1
- func CopyMoreTo[T interface{}, T1 interface{}](data []*T, list []*T1) []*T1
- func CopyTo[T interface{}, T1 interface{}](data *T, target *T1) *T1
- func CurrentPath() string
- func DecodeBase64(s string) ([]byte, error)
- func EncodeBase64(b []byte) string
- func EnsureDir(dirPath string) error
- func ErrConvertMoreTo[T any, T1 any](list []T, ty []T1) ([]T1, error)
- func ErrCopyTo[T interface{}, T1 interface{}](data *T, target *T1) (*T1, error)
- func FileExt(file string) string
- func FindStrBetweenStr(s string, left, right string) string
- func FmtPageParams(pageNum, pageSize int64) (int64, int64)
- func GetAccessKey() string
- func GetAccessSecret() string
- func GetDigProvider[T interface{}](di *dig.Container) T
- func GetLocalIp() (ipv4 string, err error)
- func GetRequestIp(r *http.Request) string
- func InDigProvider[T interface{}](di *dig.Container) bool
- func InStringArray(s string, arr []string) bool
- func Interface2Float64(d interface{}) float64
- func Interface2Int64(d interface{}) int64
- func InterfaceToArray(records interface{}) []interface{}
- func InterfaceToSqlString(a interface{}) string
- func InterfaceToString(value interface{}) string
- func IsExistPath(path string) bool
- func IsNil(t interface{}) bool
- func KeepHasPrefix(s string, prefix string) string
- func KeepHasSuffix(s string, suffix string) string
- func LookupArray[T any](list []T, f func(T, int))
- func LookupMap[T string | int | int64, T1 any](m map[T]T1, f func(T, T1))
- func LoopDo(f func() bool, dur time.Duration) func()
- func LoopDoI(f func(int64) bool, dur time.Duration) func()
- func LoopHandler[T interface{}](list []T, h func(T))
- func MapKeys[T interface{}](data map[string]T) []string
- func Max[T int | int8 | int16 | int32 | int64 | float32 | float64](a T, b T) T
- func MaxInt(a int, b int) int
- func MaxInt64(a int64, b int64) int64
- func Md5Sum(s string) string
- func MergeMap[T interface{}](mList ...map[string]T) map[string]T
- func MergeSlice[T interface{}](sList ...[]T) []T
- func Min[T int | int8 | int16 | int32 | int64 | float32 | float64](a T, b T) T
- func MinInt(a int, b int) int
- func MinInt64(a int64, b int64) int64
- func MoreValueChooseFloat64(value float64, more ...float64) float64
- func MoreValueChooseInt64(value int64, more ...int64) int64
- func MoreValueChooseString(value string, more ...string) string
- func NewMd5Password(password string, secret string) string
- func NewRequestId() string
- func NewTrueScopeRand() *mrand.Rand
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- func PadLeftString(str string, l int, pad string) string
- func PadRightString(str string, l int, pad string) string
- func RandCode(l int, chars []string) string
- func RandFigureCode(l int) string
- func RandLetterCode(l int) string
- func RandLetterFigureCode(l int) string
- func RandNickname() string
- func RandOrderNoByDateTime(prefix string, useDate bool, useTime bool, randLen int) string
- func ReadYaml(data interface{}, yamlContent string) error
- func ReadYamlFile(data interface{}, configPath string) error
- func SaveMultipartFile(header *multipart.FileHeader, uploadDir, fileName string) (string, error)
- func ScanDirFileDo(dir string, fn func(file string, path string) error) error
- func ScanEmbedFsDo(embFs embed.FS, fn func(file string, path string) error) error
- func ScopeCreateSQLv1916(scope *gorm.Scope)
- func ScopeUpdateSQLv1916(scope *gorm.Scope)
- func SetRequestBodyJson(req *http.Request, data interface{}) error
- func Signature(params ...string) string
- func SliceInt64ToMap(src []int64) map[int64]bool
- func StringIntId(s string) int
- func StringToBytes(s string) []byte
- func TrueScopeRand[T int | int64 | float64](min T, max T) T
- func TrueScopeRandNoSafe(min int64, max int64) int64
- func UnixMilliFixUnit(timestamp int64, unit int64) int64
- func UnixMilliToMonth(timestamp int64, zone string) (int64, error)
- func UnixMilliToYear(timestamp int64, zone string) (int64, error)
- func UnixMilliToZeroHour(timestamp int64, zone string) (int64, error)
- type TaoBaoIpData
- type TaoBaoIpResult
Constants ¶
This section is empty.
Variables ¶
var FilePathExist = IsExistPath
FilePathExist 文件路径是否存在
Functions ¶
func AesDecrypt ¶
AesDecrypt AES解密
func AesEncrypt ¶
AesEncrypt AES加密,CBC 注意:aes密钥key的长度必须为16,24,32个字符
func ArrayDifference ¶ added in v1.0.4
func ArrayDifference[T interface{}](slices ...[]T) []T
ArrayDifference 取数组差集
func ArrayIntersection ¶ added in v1.0.4
func ArrayIntersection[T interface{}](slices ...[]T) []T
ArrayIntersection 取数组交集
func ArrayUnion ¶ added in v1.0.4
func ArrayUnion[T interface{}](slices ...[]T) []T
ArrayUnion 取数组并集
func Base64Decode ¶
func Base64Encode ¶
func BytesToString ¶
BytesToString converts byte slice to string without a memory allocation.
func CBCEncrypt ¶
CBCEncrypt CBC加密
func CapturePanic ¶
func CapturePanic() (has bool)
func CompareVersion ¶
CompareVersion 比较版本,-1:小于,0:相等,1:大于 v1.1.1 compare v1.2.1
func ConvertMoreTo ¶
ConvertMoreTo 转换为对应的接口(多个进行转换处理)
func CopyMap ¶ added in v1.0.4
func CopyMap[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64 | string | struct{}, T1 interface{}](m map[T]T1) map[T]T1
CopyMap 复制map
func CopyMoreTo ¶
func CopyMoreTo[T interface{}, T1 interface{}](data []*T, list []*T1) []*T1
CopyMoreTo 浅拷贝数组,data=>target
func CopyTo ¶
func CopyTo[T interface{}, T1 interface{}](data *T, target *T1) *T1
CopyTo 浅拷贝,data=>target
func ErrConvertMoreTo ¶
ErrConvertMoreTo 转换为对应的类型(多个进行转换处理),返回error
func ErrCopyTo ¶
func ErrCopyTo[T interface{}, T1 interface{}](data *T, target *T1) (*T1, error)
ErrCopyTo 浅拷贝(范围error),data=>target
func FindStrBetweenStr ¶
FindStrBetweenStr 查找left和right字符串中间的字符串
func FmtPageParams ¶
func GetAccessSecret ¶ added in v1.0.1
func GetAccessSecret() string
GetAccessSecret 获取一个accessSecret,通常为30个字符
func GetDigProvider ¶ added in v1.0.2
GetDigProvider 获取指定provider
func InDigProvider ¶
InDigProvider 是否在dig中已提供provider
func InStringArray ¶
func Interface2Float64 ¶
func Interface2Float64(d interface{}) float64
Interface2Float64 任意值转float64
func InterfaceToArray ¶
func InterfaceToArray(records interface{}) []interface{}
InterfaceToArray 转换任意interface{}为数组interface{}
func InterfaceToSqlString ¶
func InterfaceToSqlString(a interface{}) string
func InterfaceToString ¶ added in v1.0.2
func InterfaceToString(value interface{}) string
InterfaceToString 将接口转换为字符串
func LookupArray ¶ added in v1.0.2
LookupArray 转换为对应的接口(多个进行转换处理)
func MoreValueChooseFloat64 ¶
MoreValueChooseFloat64 多个值选择string,若没有more则默认value,有more则选择more的第一个
func MoreValueChooseInt64 ¶
MoreValueChooseInt64 多个值选择int64,若没有more则默认value,有more则选择more的第一个
func MoreValueChooseString ¶
MoreValueChooseString 多个值选择string,若没有more则默认value,有more则选择more的第一个
func NewMd5Password ¶
func NewRequestId ¶
func NewRequestId() string
func NewTrueScopeRand ¶
func PadLeftString ¶
PadLeftString 左填充字符串至指定长度
func PadRightString ¶
PadRightString 右填充字符串至指定长度
func RandLetterFigureCode ¶
RandLetterFigureCode 字母(大小写都包含)+数字 如需纯大写或纯小写,自行转换 strings.ToLower
func RandOrderNoByDateTime ¶
RandOrderNoByDateTime 按日期生成单据编号,类似: TX202404230714209992
func ReadYamlFile ¶
func SaveMultipartFile ¶ added in v1.0.2
func SaveMultipartFile(header *multipart.FileHeader, uploadDir, fileName string) (string, error)
SaveMultipartFile 保存文件
func ScanDirFileDo ¶
ScanDirFileDo 扫描目录文件并执行操作
func ScanEmbedFsDo ¶
ScanEmbedFsDo 扫描文件操作 注意:下划线文件不会被 embed.FS 嵌入打包进来
func ScopeCreateSQLv1916 ¶
ScopeCreateSQLv1916 使用gorm scope生成create sql和vars(适用于gorm v1.9.16版本) copy from gorm source code scope.SQL, scope.SQLVars
func ScopeUpdateSQLv1916 ¶
ScopeUpdateSQLv1916 使用gorm scope生成update sql和vars(适用于gorm v1.9.16版本) copy from gorm source code scope.SQL, scope.SQLVars
func SetRequestBodyJson ¶ added in v1.0.2
func StringToBytes ¶
StringToBytes converts string to byte slice without a memory allocation.
func TrueScopeRand ¶
TrueScopeRand 真随机数,范围随机,min<= V <max
func TrueScopeRandNoSafe ¶
TrueScopeRandNoSafe 真随机数(非并发安全) 全局使用一个rand的情况下会引发数组panic(未知原因)
func UnixMilliFixUnit ¶ added in v1.0.1
UnixMilliFixUnit 毫秒级时间戳按unit取整
func UnixMilliToMonth ¶ added in v1.0.1
UnixMilliToMonth 毫秒级时间戳转换为每月1号凌晨时间戳
func UnixMilliToYear ¶ added in v1.0.1
UnixMilliToYear 毫秒级时间戳转换为每年1月1号凌晨时间戳
Types ¶
type TaoBaoIpData ¶
type TaoBaoIpData struct {
QueryIp string `json:"queryIp"`
Ip string `json:"ip"`
//国家
CountyId interface{} `json:"county_id"`
County string `json:"county"`
//
CountryId string `json:"country_id"`
Country string `json:"country"`
//区域
AreaId string `json:"area_id"`
Area string `json:"area"`
//如浙江
RegionId string `json:"region_id"`
Region string `json:"region"`
//城市,如:杭州
CityId string `json:"city_id"`
City string `json:"city"`
//运营商,如电信
IspId string `json:"isp_id"`
Isp string `json:"isp"`
}
func ParseIpByTaoBao ¶
func ParseIpByTaoBao(ip string) (TaoBaoIpData, error)
ParseIpByTaoBao 解析ip来源(淘宝解析) 具体查看: https://ip.taobao.com/instructions 可能会有限流,使用时最好注意下sleep间隔
type TaoBaoIpResult ¶
type TaoBaoIpResult struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data TaoBaoIpData `json:"data"`
}
TaoBaoIpResult 淘宝ip来源解析请求结果,结果示例:
{
"data": {
"area": "",
"country": "中国",
"isp_id": "1000114",
"queryIp": "210.75.225.254",
"city": "北京",
"ip": "210.75.225.254",
"isp": "科技网",
"county": "",
"region_id": "110000",
"area_id": "",
"county_id": null,
"region": "北京",
"country_id": "CN",
"city_id": "110100"
},
"msg": "query success",
"code": 0
}