helper

package
v0.0.0-...-df13ac1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToInts

func AnyToInts[T comparable](numbers []T) []int

AnyToInts 将任何类型的切片转化成int切片

func AnyToUint64

func AnyToUint64[T comparable](numbers []T) []uint64

AnyToUint64 将任何类型的切片转化成uin64t切片

func ArrayChunk

func ArrayChunk[T any](arr []T, size int) [][]T

ArrayChunk 数组分组

func ConvertSlice2MapIdKey

func ConvertSlice2MapIdKey(slice interface{}, keyExtractor KeyExtractor) map[uint64]interface{}

ConvertSlice2MapIdKey slice 转换为map ,key采用通用的id

func GenerateAppCode

func GenerateAppCode(mchId uint64) string

商家开放平台code

func GenerateAppKeyPair

func GenerateAppKeyPair() (string, string)

GenerateAppKeyPair 生成应用的AK和SK密钥对 返回值: appKey string, appSecret string

func GenerateBaseSnowId

func GenerateBaseSnowId(num int, n *snowflake.Node) string

GenerateBaseSnowId 生成雪花算法ID 废弃

func GenerateClientId

func GenerateClientId() string

func GenerateCode

func GenerateCode(length int) string

GenerateCode 随机生成n位验证码

func GenerateHash

func GenerateHash(str string) string

GenerateHash 生成md5 hash值

func GenerateId

func GenerateId() string

GenerateId 生成随机id

func GeneratePasswordHash

func GeneratePasswordHash(password string, salt string) string

GeneratePasswordHash 生成密码hash值

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString 生成随机字符串

func GenerateSeqNo

func GenerateSeqNo(prefix string, mchId uint64) string

GenerateSeqNo 生成业务流水编号 前缀: 发票:FP 账单:ZD 交易:JY 提现:TX 充值:CZ 汇款:HK 开通:KT 格式:{前缀}{YYMMDDHHmmss}{商家ID(6-8位)}{随机数字(4-6位)}

func GenerateUUID

func GenerateUUID() int64

GenerateUUID 生成唯一ID

func GenerateUuid

func GenerateUuid(size int) string

GenerateUuid 生成随机字符串

func GetAllDirs

func GetAllDirs(root string) ([]string, error)

GetAllDirs 获取指定文件夹中所有文件夹路径

func GetDeliveryTime

func GetDeliveryTime(distance int, startDistance int, startTime int, addDistance int, addTime int) int

GetDeliveryTime 计算配送时间 配送时间默认3000m以内60分钟,超过1000m增加5分钟,返回秒

func GetFileNamesByDirPath

func GetFileNamesByDirPath(root string) ([]map[string]interface{}, error)

GetFileNamesByDirPath 获取当前文件夹下的所有文件和文件夹名称(包括子文件夹和文件)

func GetKeyByMap

func GetKeyByMap[T comparable](m map[string]T, value T) string

GetKeyByMap 根据map中的值获取键

func GetLocalIp

func GetLocalIp() (string, error)

GetLocalIp 获取本机ip

func GetLocalIpToInt

func GetLocalIpToInt() (int, error)

GetLocalIpToInt 获取本机IP转成int

func GetProjectModuleName

func GetProjectModuleName() string

GetProjectModuleName 获取当前项目的module名称

func GetStructColumnName

func GetStructColumnName(s interface{}, _type int) ([]string, error)

GetStructColumnName 获取结构体中的字段名称 _type: 1: 获取tag字段值 2:获取结构体字段值

func GetUploadFileBytes

func GetUploadFileBytes(file *multipart.FileHeader) ([]byte, error)

GetUploadFileBytes 获取上传文件的数据流

func InAnyKeyMap

func InAnyKeyMap[T comparable, V comparable](haystack map[T]V, needle T) bool

InAnyKeyMap 判断某个map的键是否存在

func InAnyMap

func InAnyMap[T comparable](haystack map[string]T, needle T) bool

InAnyMap 判断某个map的值是否存在

func InAnySlice

func InAnySlice[T comparable](haystack []T, needle T) bool

InAnySlice 判断某个字符串是否在字符串切片中

func IntsToString

func IntsToString[T any](numbers []T, sep string) string

IntsToString 将int切片转换成字符串

func IsPathExist

func IsPathExist(path string) bool

IsPathExist 判断所给路径文件/文件夹是否存在

func IsValidEmail

func IsValidEmail(email string) bool

IsValidEmail 验证邮箱格式

func IsValidPhone

func IsValidPhone(phone string) bool

IsValidPhone 验证手机号格式

func MakeFileOrPath

func MakeFileOrPath(path string) (*os.File, error)

MakeFileOrPath 创建文件/文件夹

func MakeMultiDir

func MakeMultiDir(filePath string) error

MakeMultiDir 调用os.MkdirAll递归创建文件夹

func MakeTimeFormatDir

func MakeTimeFormatDir(rootPath, pathName, timeFormat string) (string, error)

MakeTimeFormatDir 创建时间格式的目录 如:upload/{path}/2023-01-07/

rootPath	根目录   pathName	子目录名称  timeFormat	时间格式	如:2006-01-02、20060102

func RandString

func RandString(length int) string

RandString 随机字符串

func ReadLocalFile

func ReadLocalFile(filePath string) ([]byte, error)

ReadLocalFile 读取本地文件并返回字节数组数据

func String2Int

func String2Int(strArr []string) []int

String2Int 将数组的string转int

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

StructToMap 使用反射将结构体转换为 map

func ToCamelCase

func ToCamelCase(s string) string

ToCamelCase 将字符串转换成驼峰写法

func ToPointer

func ToPointer[T comparable](s T) *T

ToPointer 将任何类型转化成指针类型

func ValidateAppKeyPair

func ValidateAppKeyPair(appKey string, appSecret string) bool

ValidateAppKeyPair 验证AK/SK密钥对格式是否合法

func WriteBytesToFile

func WriteBytesToFile(data []byte, filePath string) error

WriteBytesToFile 将字节数组数据写入本地文件

func WriteContentToFile

func WriteContentToFile(file *multipart.FileHeader, filePath string) error

WriteContentToFile 将文件内容写入指定路径

Types

type KeyExtractor

type KeyExtractor func(interface{}) uint64

Jump to

Keyboard shortcuts

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