Documentation
¶
Index ¶
- Constants
- Variables
- func AnyToArr(data interface{}) []interface{}
- func AnyToFloat64(data interface{}) float64
- func AnyToInt(data interface{}) int
- func AnyToInt64(data interface{}) int64
- func AnyToJson(data interface{}) (string, error)
- func AnyToJsonB(data interface{}) ([]byte, error)
- func AnyToMap(data interface{}) map[string]interface{}
- func AnyToString(i interface{}) string
- func AnyToStrings(data interface{}) []string
- func BitToByte(b []uint8) []byte
- func BoolToByte(b bool) []byte
- func ByteToBinaryString(data byte) (str string)
- func ByteToBit(b []byte) []uint8
- func ByteToBool(b []byte) bool
- func ByteToFloat32(b []byte) float32
- func ByteToFloat64(b []byte) float64
- func ByteToGBK(strBuf []byte) []byte
- func ByteToInt(b []byte) int
- func ByteToInt64(b []byte) int64
- func ByteToStr(b []byte) string
- func Close()
- func Debug(args ...interface{})
- func DebugF(format string, args ...interface{})
- func DebugFTimes(times int, format string, args ...interface{})
- func DebugTimes(times int, args ...interface{})
- func DecodeByte(b []byte) (interface{}, error)
- func DeepCopy[T any](dst, src T) error
- func DeepEqual(a, b interface{}) bool
- func DisableTerminal()
- func EncodeByte(v interface{}) []byte
- func Error(args ...interface{})
- func ErrorF(format string, args ...interface{})
- func ErrorFTimes(times int, format string, args ...interface{})
- func ErrorTimes(times int, args ...interface{})
- func FileExists(name string) bool
- func FileMd5sum(fileName string) string
- func Float32ToByte(f float32) []byte
- func Float32ToUint32(f float32) uint32
- func Float64ToByte(f float64) []byte
- func Float64ToUint64(f float64) uint64
- func Get16MD5Encode(data string) string
- func GetAliYunOSSClient(tag string) *oss.Bucket
- func GetAllFile(pathname string) ([]string, error)
- func GetDate() string
- func GetMD5Encode(data string) string
- func GetMinioClient(tag string) *minio.Client
- func GetMongoDBConn(tag string) *mongo.Database
- func GetMysqlConn(tag string) *gorm.DB
- func GetPgsqlConn(tag string) *sql.DB
- func GetRedisConn(tag string) *redis.Client
- func GetTencentCOSClient(tag string) *cos.Client
- func GetUUID() string
- func HexToInt(s string) int
- func HexToInt64(s string) int64
- func ID() int64
- func ID64() (int64, error)
- func IDMd5() string
- func IDStr() string
- func Info(args ...interface{})
- func InfoF(format string, args ...interface{})
- func InfoFTimes(times int, format string, args ...interface{})
- func InfoTimes(times int, args ...interface{})
- func InitConf(path string)
- func Int64ToByte(i int64) []byte
- func Int64ToHex(i int64) string
- func Int64ToStr(i int64) string
- func IntToByte(i int) []byte
- func IntToHex(i int) string
- func IsUtf8(buf []byte) bool
- func JsonToMap(str string) (map[string]interface{}, error)
- func MD5(str string) string
- func MapStrToAny(m map[string]string) map[string]interface{}
- func MapToJson(m interface{}) (string, error)
- func MinioCreateBucket(client *minio.Client, ctx context.Context, bucketName string) error
- func MinioDeleteBucket(client *minio.Client, ctx context.Context, bucketName string) error
- func MinioDeleteObject(client *minio.Client, ctx context.Context, bucketName, objectName string) error
- func MinioDownloadFile(client *minio.Client, ctx context.Context, ...) error
- func MinioGenerateSignedURL(client *minio.Client, ctx context.Context, bucketName, objectName string) (string, error)
- func MinioListObjects(client *minio.Client, ctx context.Context, bucketName string) error
- func MinioUploadFile(client *minio.Client, ctx context.Context, ...) error
- func NowTimestampStr() string
- func P2E()
- func Panic(args ...interface{})
- func PanicToError(fn func()) (err error)
- func PathMkdir(path string)
- func Print(args ...interface{})
- func PrintF(format string, args ...interface{})
- func RandomIntCaptcha(captchaLen int) string
- func SetAppName(name string)
- func SetLogFile(dir, name string, maxDay int)
- func SetOutService(ip string, port int)
- func SetOutServiceInfo2Panic()
- func SetOutServiceWarn2Panic()
- func SliceContains[V comparable](a []V, v V) bool
- func SliceCopy[V comparable](a []V) []V
- func SliceDeduplicate[V comparable](a []V) []V
- func SliceDel[V comparable](a []V, i int) []V
- func SliceMax[V number](a []V) V
- func SliceMin[V number](a []V) V
- func SlicePop[V comparable](a []V) (V, []V)
- func SliceRand[V comparable](a []V) V
- func SliceReverse[V comparable](a []V) []V
- func SliceShuffle[V comparable](a []V) []V
- func StrNumToFloat32(str string) float32
- func StrNumToFloat64(str string) float64
- func StrNumToInt(str string) int
- func StrNumToInt32(str string) int32
- func StrNumToInt64(str string) int64
- func StrToByte(s string) []byte
- func StructToMap(obj interface{}) map[string]interface{}
- func StructToMapV2(obj interface{}, hasValue bool) (map[string]interface{}, error)
- func StructToMapV3(obj interface{}) map[string]interface{}
- func TencentCOSCheckIsExist(cosClient *cos.Client, keyName string) bool
- func TimeHM(t time.Time) string
- func TimeStr2Unix(timeStr string) int64
- func TimeStr2UnixByLayOut(layout, timeStr string) int64
- func TimeToYMD(t time.Time) string
- func TimeToYMDHMS(t time.Time) string
- func TimeYMDCN(t time.Time) string
- func Timestamp2Time(timestamp int64) time.Time
- func Timestamp2Week(timestamp int64) string
- func TimestampSubDay(timestamp int64) int64
- func Uint8ToStr(bs []uint8) string
- func Warn(args ...interface{})
- func WarnF(format string, args ...interface{})
- func WarnFTimes(times int, format string, args ...interface{})
- func WarnTimes(times int, args ...interface{})
- type AliYunOSS
- type FileInfo
- type GormLogger
- func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})
- func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})
- func (l *GormLogger) LogMode(lev gormLogger.LogLevel) gormLogger.Interface
- func (l *GormLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})
- type IdWorker
- type Level
- type MinIOConf
- type MongoDBConf
- type MysqlConf
- type PgsqlConf
- type RedisConf
- type TenCentCOS
Constants ¶
const ( TimeTemplate = "2006-01-02 15:04:05" TimeTemplateNotSec = "2006-01-02 15:04" )
Variables ¶
var AliYunOSSClient map[string]*oss.Bucket
var Conf conf
var LevelMap = map[Level]string{
0: "[Print] ",
1: "[INFO] ",
2: "[DEBUG] ",
3: "[WARN] ",
4: "[ERROR] ",
5: "[PANIC] ",
6: "[Http]",
}
var MinioClient map[string]*minio.Client
var MongoDBConn map[string]*mongo.Database
var MysqlConn map[string]*gorm.DB
var PgsqlConn map[string]*sql.DB
var RedisConn map[string]*redis.Client
var TencentCOSClient map[string]*cos.Client
Functions ¶
func AnyToJsonB ¶
AnyToJsonB interface{} -> json string
func AnyToMap ¶
func AnyToMap(data interface{}) map[string]interface{}
AnyToMap interface{} -> map[string]interface{}
func AnyToStrings ¶
func AnyToStrings(data interface{}) []string
AnyToStrings interface{} -> []string
func ByteToBinaryString ¶
ByteToBinaryString 字节 -> 二进制字符串
func DebugFTimes ¶
func DebugTimes ¶
func DebugTimes(times int, args ...interface{})
func DeepEqual ¶
func DeepEqual(a, b interface{}) bool
DeepEqual 深度比较任意类型的两个变量的是否相等,类型一样值一样反回true 如果元素都是nil,且类型相同,则它们是相等的; 如果它们是不同的类型,它们是不相等的
func DisableTerminal ¶
func DisableTerminal()
func ErrorFTimes ¶
func ErrorTimes ¶
func ErrorTimes(times int, args ...interface{})
func FileExists ¶
func GetAliYunOSSClient ¶
func GetMinioClient ¶
func GetMongoDBConn ¶
func GetMysqlConn ¶
func GetPgsqlConn ¶
func GetRedisConn ¶
func GetTencentCOSClient ¶
func InfoFTimes ¶
InfoFTimes times 意思是打印第几级函数调用
func MapStrToAny ¶
MapStrToAny map[string]string -> map[string]interface{}
func MinioCreateBucket ¶
MinioCreateBucket 创建存储桶
func MinioDeleteBucket ¶
MinioDeleteBucket 删除存储桶
func MinioDeleteObject ¶
func MinioDeleteObject(client *minio.Client, ctx context.Context, bucketName, objectName string) error
MinioDeleteObject 删除对象
func MinioDownloadFile ¶
func MinioDownloadFile(client *minio.Client, ctx context.Context, bucketName, objectName, destinationPath string) error
MinioDownloadFile 下载文件
func MinioGenerateSignedURL ¶
func MinioGenerateSignedURL(client *minio.Client, ctx context.Context, bucketName, objectName string) (string, error)
MinioGenerateSignedURL 生成预签名 URL
func MinioListObjects ¶
MinioListObjects 列出存储桶中的对象
func MinioUploadFile ¶
func MinioUploadFile(client *minio.Client, ctx context.Context, bucketName, objectName, filePath, contentType string) error
MinioUploadFile 上传文件
func NowTimestampStr ¶
func NowTimestampStr() string
func RandomIntCaptcha ¶
RandomIntCaptcha 生成 captchaLen 位随机数,理论上会重复
func SetLogFile ¶
SetLogFile 设置日志文件名称, 文件名称可含路径(绝对或相对)
func SetOutService ¶
func SetOutServiceInfo2Panic ¶
func SetOutServiceInfo2Panic()
func SetOutServiceWarn2Panic ¶
func SetOutServiceWarn2Panic()
func SliceContains ¶
func SliceContains[V comparable](a []V, v V) bool
func SliceCopy ¶
func SliceCopy[V comparable](a []V) []V
func SliceDeduplicate ¶
func SliceDeduplicate[V comparable](a []V) []V
func SliceDel ¶
func SliceDel[V comparable](a []V, i int) []V
func SlicePop ¶
func SlicePop[V comparable](a []V) (V, []V)
func SliceRand ¶
func SliceRand[V comparable](a []V) V
func SliceReverse ¶
func SliceReverse[V comparable](a []V) []V
func SliceShuffle ¶
func SliceShuffle[V comparable](a []V) []V
func StructToMap ¶
func StructToMap(obj interface{}) map[string]interface{}
StructToMap struct -> map[string]interface{}
func StructToMapV2 ¶
StructToMapV2 Struct -> map hasValue=true表示字段值不管是否存在都转换成map hasValue=false表示字段为不为空或者不为0则转换成map
func StructToMapV3 ¶
func StructToMapV3(obj interface{}) map[string]interface{}
StructToMapV3 struct -> map
func TencentCOSCheckIsExist ¶
TencentCOSCheckIsExist 检查文件是否存在
func TimeStr2Unix ¶
func TimeStr2UnixByLayOut ¶
func TimeToYMDHMS ¶
func Timestamp2Time ¶
func Timestamp2Week ¶
func TimestampSubDay ¶
func WarnFTimes ¶
Types ¶
type GormLogger ¶
func NewGormLogger ¶
func NewGormLogger() *GormLogger
func (*GormLogger) Error ¶
func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})
func (*GormLogger) Info ¶
func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})
func (*GormLogger) LogMode ¶
func (l *GormLogger) LogMode(lev gormLogger.LogLevel) gormLogger.Interface
type IdWorker ¶
type IdWorker struct {
// contains filtered or unexported fields
}
IdWorker 雪花Id
func (*IdWorker) InitIdWorker ¶
type MongoDBConf ¶
type MongoDBConf struct {
Tag string `yaml:"tag"` // 标记,通过标记获得连接
Host string `yaml:"host"`
Port int64 `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
MaxPoolSize int64 `yaml:"maxPoolSize"` // 连接池最大数 默认100
MaxConnIdleTime int64 `yaml:"maxConnIdleTime"` // 连接池中保持空闲的最长时间,单位秒 默认300
ConnectTimeout int64 `yaml:"connectTimeout"` // 连接超时,单位秒 默认30
IsSSH bool `yaml:"isSSH"` // t:开启 f:关闭
SSHUsername string `yaml:"sshUser"` // ssh 账号
SSHPassword string `yaml:"sshPassword"` // ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
SSHPrivateKey string `yaml:"sshPrivateKey"` // ssh 密钥文件路径
SSHRemoteHost string `yaml:"sshRemoteHost"` // ssh 服务器地址
SSHRemotePort int64 `yaml:"sshRemotePort"` // ssh 服务器端口
}
type MysqlConf ¶
type MysqlConf struct {
Tag string `yaml:"tag"` // 标记,通过标记获得连接
User string `yaml:"user"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port int64 `yaml:"port"`
Database string `yaml:"database"`
DisablePrepared bool `yaml:"disablePrepared"` // 是否禁用预编译
MaxIdle int64 `yaml:"maxIdle"` // 最大空闲连接数
MaxOpen int64 `yaml:"maxOpen"` // 最大连接数
MaxLifeTime int64 `yaml:"maxLife"` // 连接最大存活时间 单位ms
MaxIdleTime int64 `yaml:"maxIdleTime"` // 连接最大空闲时间 单位ms
IsSSH bool `yaml:"isSSH"` // t:开启 f:关闭
SSHUsername string `yaml:"sshUser"` // ssh 账号
SSHPassword string `yaml:"sshPassword"` // ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
SSHPrivateKey string `yaml:"sshPrivateKey"` // ssh 密钥文件路径
SSHRemoteHost string `yaml:"sshRemoteHost"` // ssh 服务器地址
SSHRemotePort int64 `yaml:"sshRemotePort"` // ssh 服务器端口
}
type PgsqlConf ¶
type PgsqlConf struct {
Tag string `yaml:"tag"` // 标记,通过标记获得连接
User string `yaml:"user"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port int64 `yaml:"port"`
Database string `yaml:"database"`
MaxIdle int64 `yaml:"maxIdle"` // 最大空闲连接数
MaxOpen int64 `yaml:"maxOpen"` // 最大连接数
MaxLifeTime int64 `yaml:"maxLife"` // 连接最大存活时间 单位ms
IsSSH bool `yaml:"isSSH"` // t:开启 f:关闭
SSHUsername string `yaml:"sshUser"` // ssh 账号
SSHPassword string `yaml:"sshPassword"` // ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
SSHPrivateKey string `yaml:"sshPrivateKey"` // ssh 密钥文件路径
SSHRemoteHost string `yaml:"sshRemoteHost"` // ssh 服务器地址
SSHRemotePort int64 `yaml:"sshRemotePort"` // ssh 服务器端口
}
type RedisConf ¶
type RedisConf struct {
Tag string `yaml:"tag"` // 标记,通过标记获得连接
Host string `yaml:"host"`
Port int `yaml:"port"`
DB int `yaml:"db"`
Password string `yaml:"password"`
PoolSize int `yaml:"poolSize"`
MinIdleConn int `yaml:"minIdleConn"` // 最小空闲连接数
ConnMaxIdleTime int `yaml:"connMaxIdleTime"` // 连接处于空闲状态的最长时间 单位秒
IsSSH bool `yaml:"isSSH"` // t:开启 f:关闭
SSHUsername string `yaml:"sshUser"` // ssh 账号
SSHPassword string `yaml:"sshPassword"` // ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
SSHPrivateKey string `yaml:"sshPrivateKey"` // ssh 密钥文件路径
SSHRemoteHost string `yaml:"sshRemoteHost"` // ssh 服务器地址
SSHRemotePort int64 `yaml:"sshRemotePort"` // ssh 服务器端口
}
type TenCentCOS ¶
type TenCentCOS struct {
Tag string `yaml:"tag"` // 标记,通过标记获得连接
SecretId string `yaml:"secretId"` // secret Id
SecretKey string `yaml:"secretKey"` // secret Key
BucketURL string `yaml:"bucketUrl"` // bucket url
}
TenCentCOS 腾讯对象存储连接配置 用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140