dbHelper

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 46 Imported by: 0

README

dbHelper

db助手,解决高效跨平台跨服务处理数据程序编写的帮助支持库,配置管理各种连接; 配置使用的yaml

使用

go get github.com/mangenotwork/dbHelper
mysql 配置
mysql:
  - tag: "" # 标记,通过标记获得连接
    user: "root" # 用户名
    password: "" # 密码
    host: "" # mysql主机
    port: 3306 # mysql端口
    database: "" # 数据库名
    disablePrepared: false # 是否禁用预编译
    maxIdle: 0 # 最大空闲连接数, 设置0或不设置为默认值
    maxOpen: 0 # 最大连接数, 设置0或不设置为默认值
    maxLife: 0 # 连接最大存活时间 单位ms, 设置0或不设置为默认值
    maxIdleTime: 0 # 连接最大空闲时间 单位ms, 设置0或不设置为默认值
    isSSH: false # true:开启  false:关闭
    sshUser: "" # ssh 账号
    sshPassword: "" # ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
    sshPrivateKey: "" # ssh 密钥文件路径
    sshRemoteHost: "" # ssh 服务器地址
    sshRemotePort: 22  # ssh 服务器端口
mysql 获取连接

mysql使用的是gorm.io/gorm库,获取的连接是*gorm.DB

...
    dbHelper.InitConf("./conf.yaml")
	conn := dbHelper.GetMysqlConn("tag")
	var data map[string]interface{}
	err := conn.Raw("select * from user limit 1").Scan(&data).Error
	if err != nil {
		dbHelper.Error(err)
	}
	dbHelper.Info(data)
...
redis 配置
redis:
  - tag: "" # 标记,通过标记获得连接
    host: ""
    port: 6379
    db: 0
    password: ""
    poolSize: 10
    minIdleConn: 5  # 最小空闲连接数
    connMaxIdleTime: 60   # 连接处于空闲状态的最长时间 单位秒
    isSSH: false # true:开启  false:关闭
    sshUser: "" # ssh 账号
    sshPassword: "" # ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
    sshPrivateKey: "" # ssh 密钥文件路径
    sshRemoteHost: "" # ssh 服务器地址
    sshRemotePort: 22  # ssh 服务器端口
redis 获取连接

redis 使用的是 github.com/go-redis/redis/v9 库,获取的连接是 *redis.Client

...
    dbHelper.InitConf("./conf.yaml")
    redisConn := dbHelper.GetRedisConn("btest")
	val, err := redisConn.Conn().Get(context.Background(), "key").Result()
	if err != nil {
		dbHelper.ErrorF("Failed to get key: %v", err)
	}
	dbHelper.Info("Key value:", val)
...
mongoDB 配置
mongoDB:
  - tag: "" # 标记,通过标记获得连接
    host: ""
    port: 27017
    user: ""
    password: ""
    database: ""
    maxPoolSize: 0     # 连接池最大数 默认100
    maxConnIdleTime: 0 # 连接池中保持空闲的最长时间,单位秒 默认300
    connectTimeout: 0  # 连接超时,单位秒 默认30
    isSSH: false # true:开启  false:关闭
    sshUser: "" # ssh 账号
    sshPassword: "" # ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
    sshPrivateKey: "" # ssh 密钥文件路径
    sshRemoteHost: "" # ssh 服务器地址
    sshRemotePort: 22  # ssh 服务器端口
mongoDB 获取连接

使用库 go.mongodb.org/mongo-driver/mongo 保存连接是 *mongo.Database

...
    dbHelper.InitConf("./conf.yaml")
	mongoConn := dbHelper.GetMongoDBConn("tag")
	collections, err := mongoConn.ListCollectionNames(context.Background(), bson.D{})
	if err != nil {
		dbHelper.ErrorF("List collections failed: %v", err)
	}
	dbHelper.Info("Collections:", collections)
...
postgreSQL 配置
pgsql:
  - tag: "test" # 标记,通过标记获得连接
    user: ""
    password: ""
    host: ""
    port: 0
    database: ""
    maxIdle: 0 # 最大空闲连接数
    maxOpen: 0 # 最大连接数
    maxLife: 0 # 连接最大存活时间 单位ms
    isSSH: false # true:开启  false:关闭
    sshUser: "" # ssh 账号
    sshPassword: "" # ssh 密码认证; 当SSHPrivateKey同时设置,优先使用密钥认证
    sshPrivateKey: "" # ssh 密钥文件路径
    sshRemoteHost: "" # ssh 服务器地址
    sshRemotePort: "" # ssh 服务器端口
postgreSQL 获取连接

使用的 _ "github.com/lib/pq" 库,保存连接是 *sql.DB

...
    dbHelper.InitConf("./conf.yaml")
	conn := dbHelper.GetPgsqlConn("tag")
	var data map[string]interface{}
	err := conn.QueryRow("select * from user limit 1").Scan(&data)
    if err != nil {
        dbHelper.Error(err)
    }
	dbHelper.Info(data)
...
对象存储 MinIO 配置
minio:
  - tag: ""      # 标记,通过标记获得连接
    endpoint: "" # MinIO 服务器地址
    accessKeyId: "" # 访问密钥 ID
    accessKeySecret: "" # 秘密访问密钥
    useSSL: false # 是否使用 SSL
对象存储 MinIO 获取连接
  • github.com/minio/minio-go/v7 获取的是 *minio.Client
dbHelper.InitConf("./conf.yaml")
client := dbHelper.GetMinioClient("dev")
client.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
...
阿里云对象存储 配置
aliYunOSS:
   - tag: ""      # 标记,通过标记获得连接
     endpoint: "" # OSS访问域名,如:oss-cn-hangzhou.aliyuncs.com
     accessKeyId: ""
     accessKeySecret: ""
     bucketName: ""
阿里云对象存储 获取连接
  • github.com/aliyun/aliyun-oss-go-sdk/oss
dbHelper.InitConf("./conf.yaml")
bucket := dbHelper.GetAliYunOSSClient("dev")
localFile := "./a.txt"
objectKey := "a.txt"
bucket.PutObjectFromFile(objectKey, localFile)
腾讯云对象存储 配置

用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140

tencentCOS:
  - tag: "dev" # 标记,通过标记获得连接
    secretId: ""  # secret Id
    secretKey: ""  # secret Key
    bucketUrl: ""  # bucket url
腾讯云对象存储 获取连接
  • github.com/tencentyun/cos-go-sdk-v5
dbHelper.InitConf("./conf.yaml")
devCos := dbHelper.GetTencentCOSClient("dev")
dbHelper.Info(dbHelper.TencentCOSCheckIsExist(devCos, "a.txt"))
testCos := dbHelper.GetTencentCOSClient("test")
dbHelper.Info(dbHelper.TencentCOSCheckIsExist(testCos, "a.txt"))
常用辅助函数
dbHelper.ID() int64  // 生成雪花id
dbHelper.IDMd5() string // 生成雪花id MD5
dbHelper.GetMD5Encode(data string) string // MD5编码
dbHelper.NowTimestampStr() string // 当前时间戳字符串
dbHelper.FileMd5sum(fileName string) string // 文件MD5
dbHelper.GetAllFile(pathname string) ([]string, error) // 获取指定目录下的所有文件
dbHelper.RandomIntCaptcha(captchaLen int) string // 生成 captchaLen 位随机数,理论上会重复
dbHelper.DeepEqual(a, b interface{}) bool // DeepEqual 深度比较任意类型的两个变量的是否相等,类型一样值一样反回true, 如果元素都是nil,且类型相同,则它们是相等的; 如果它们是不同的类型,它们是不相等的
dbHelper.SliceContains[V comparable](a []V, v V) bool // 判断切片a中是否包含元素v
dbHelper.SliceDeduplicate[V comparable](a []V) []V // 去重
dbHelper.AnyToString(i interface{}) string // AnyToString any -> string
dbHelper.JsonToMap(str string) (map[string]interface{}, error) // JsonToMap json -> map
dbHelper.MapToJson(m interface{}) (string, error) // MapToJson map -> json
dbHelper.AnyToMap(data interface{}) map[string]interface{} // AnyToMap interface{} -> map[string]interface{}
dbHelper.AnyToInt(data interface{}) int // AnyToInt interface{} -> int
dbHelper.AnyToInt64(data interface{}) int64 // AnyToInt64 interface{} -> int64
dbHelper.AnyToFloat64(data interface{}) float64 // AnyToFloat64 interface{} -> float64
dbHelper.AnyToStrings(data interface{}) []string // AnyToStrings interface{} -> []string
dbHelper.AnyToJson(data interface{}) (string, error) // AnyToJson interface{} -> json string
dbHelper.AnyToJsonB(data interface{}) ([]byte, error) // AnyToJsonB interface{} -> json string
dbHelper.IntToHex(i int) string // IntToHex int -> hex
dbHelper.Int64ToHex(i int64) string // Int64ToHex int64 -> hex
dbHelper.HexToInt(s string) int // HexToInt hex -> int
dbHelper.HexToInt64(s string) int64 // HexToInt64 hex -> int
dbHelper.StrNumToInt64(str string) int64 // StrNumToInt64 string -> int64
dbHelper.StrNumToInt(str string) int // StrNumToInt string -> int
dbHelper.StrNumToInt32(str string) int32 // StrNumToInt32 string -> int32
dbHelper.StrNumToFloat64(str string) float64 // StrNumToFloat64 string -> float64
dbHelper.StrNumToFloat32(str string) float32 // StrNumToFloat32 string -> float32
dbHelper.Uint8ToStr(bs []uint8) string // Uint8ToStr []uint8 -> string
dbHelper.StrToByte(s string) []byte // StrToByte string -> []byte
dbHelper.ByteToStr(b []byte) string // ByteToStr []byte -> string
dbHelper.BoolToByte(b bool) []byte // BoolToByte bool -> []byte
dbHelper.ByteToBool(b []byte) bool // ByteToBool []byte -> bool
dbHelper.IntToByte(i int) []byte // IntToByte int -> []byte
dbHelper.ByteToInt(b []byte) int // ByteToInt []byte -> int
dbHelper.Int64ToByte(i int64) []byte // Int64ToByte int64 -> []byte
dbHelper.ByteToInt64(b []byte) int64 // ByteToInt64 []byte -> int64
dbHelper.Float32ToByte(f float32) []byte // Float32ToByte float32 -> []byte
dbHelper.Float32ToUint32(f float32) uint32 // Float32ToUint32 float32 -> uint32
dbHelper.ByteToFloat32(b []byte) float32 // ByteToFloat32 []byte -> float32
dbHelper.Float64ToByte(f float64) []byte // Float64ToByte float64 -> []byte
dbHelper.Float64ToUint64(f float64) uint64 // Float64ToUint64 float64 -> uint64
dbHelper.ByteToFloat64(b []byte) float64 // ByteToFloat64 []byte -> float64
dbHelper.StructToMap(obj interface{}) map[string]interface{} // StructToMap  struct -> map[string]interface{}
dbHelper.ByteToBit(b []byte) []uint8 // ByteToBit []byte -> []uint8 (bit)
dbHelper.BitToByte(b []uint8) []byte // BitToByte []uint8 -> []byte
dbHelper.ByteToBinaryString(data byte) (str string) // ByteToBinaryString  字节 -> 二进制字符串
dbHelper.MapStrToAny(m map[string]string) map[string]interface{} // MapStrToAny map[string]string -> map[string]interface{}
dbHelper.ByteToGBK(strBuf []byte) []byte // ByteToGBK   byte -> gbk byte
    
还有其余的没有那么常用的方法...

excel操作相关辅助函数

todo...

图片处理相关辅助函数

todo...

todo list

  • excel操作相关的辅助函数
  • 图片处理相关辅助函数,压缩,裁剪,水印,缩略图等

Documentation

Index

Constants

View Source
const (
	TimeTemplate       = "2006-01-02 15:04:05"
	TimeTemplateNotSec = "2006-01-02 15:04"
)

Variables

View Source
var AliYunOSSClient map[string]*oss.Bucket
View Source
var Conf conf
View Source
var LevelMap = map[Level]string{
	0: "[Print] ",
	1: "[INFO]  ",
	2: "[DEBUG] ",
	3: "[WARN]  ",
	4: "[ERROR] ",
	5: "[PANIC] ",
	6: "[Http]",
}
View Source
var MinioClient map[string]*minio.Client
View Source
var MongoDBConn map[string]*mongo.Database
View Source
var MysqlConn map[string]*gorm.DB
View Source
var PgsqlConn map[string]*sql.DB
View Source
var RedisConn map[string]*redis.Client
View Source
var TencentCOSClient map[string]*cos.Client

Functions

func AnyToArr

func AnyToArr(data interface{}) []interface{}

AnyToArr interface{} -> []interface{}

func AnyToFloat64

func AnyToFloat64(data interface{}) float64

AnyToFloat64 interface{} -> float64

func AnyToInt

func AnyToInt(data interface{}) int

AnyToInt interface{} -> int

func AnyToInt64

func AnyToInt64(data interface{}) int64

AnyToInt64 interface{} -> int64

func AnyToJson

func AnyToJson(data interface{}) (string, error)

AnyToJson interface{} -> json string

func AnyToJsonB

func AnyToJsonB(data interface{}) ([]byte, error)

AnyToJsonB interface{} -> json string

func AnyToMap

func AnyToMap(data interface{}) map[string]interface{}

AnyToMap interface{} -> map[string]interface{}

func AnyToString

func AnyToString(i interface{}) string

AnyToString any -> string

func AnyToStrings

func AnyToStrings(data interface{}) []string

AnyToStrings interface{} -> []string

func BitToByte

func BitToByte(b []uint8) []byte

BitToByte []uint8 -> []byte

func BoolToByte

func BoolToByte(b bool) []byte

BoolToByte bool -> []byte

func ByteToBinaryString

func ByteToBinaryString(data byte) (str string)

ByteToBinaryString 字节 -> 二进制字符串

func ByteToBit

func ByteToBit(b []byte) []uint8

ByteToBit []byte -> []uint8 (bit)

func ByteToBool

func ByteToBool(b []byte) bool

ByteToBool []byte -> bool

func ByteToFloat32

func ByteToFloat32(b []byte) float32

ByteToFloat32 []byte -> float32

func ByteToFloat64

func ByteToFloat64(b []byte) float64

ByteToFloat64 []byte -> float64

func ByteToGBK

func ByteToGBK(strBuf []byte) []byte

ByteToGBK byte -> gbk byte

func ByteToInt

func ByteToInt(b []byte) int

ByteToInt []byte -> int

func ByteToInt64

func ByteToInt64(b []byte) int64

ByteToInt64 []byte -> int64

func ByteToStr

func ByteToStr(b []byte) string

ByteToStr []byte -> string

func Close

func Close()

func Debug

func Debug(args ...interface{})

func DebugF

func DebugF(format string, args ...interface{})

func DebugFTimes

func DebugFTimes(times int, format string, args ...interface{})

func DebugTimes

func DebugTimes(times int, args ...interface{})

func DecodeByte

func DecodeByte(b []byte) (interface{}, error)

DecodeByte decode byte

func DeepCopy

func DeepCopy[T any](dst, src T) error

func DeepEqual

func DeepEqual(a, b interface{}) bool

DeepEqual 深度比较任意类型的两个变量的是否相等,类型一样值一样反回true 如果元素都是nil,且类型相同,则它们是相等的; 如果它们是不同的类型,它们是不相等的

func DisableTerminal

func DisableTerminal()

func EncodeByte

func EncodeByte(v interface{}) []byte

EncodeByte encode byte

func Error

func Error(args ...interface{})

func ErrorF

func ErrorF(format string, args ...interface{})

func ErrorFTimes

func ErrorFTimes(times int, format string, args ...interface{})

func ErrorTimes

func ErrorTimes(times int, args ...interface{})

func FileExists

func FileExists(name string) bool

func FileMd5sum

func FileMd5sum(fileName string) string

FileMd5sum 文件 Md5

func Float32ToByte

func Float32ToByte(f float32) []byte

Float32ToByte float32 -> []byte

func Float32ToUint32

func Float32ToUint32(f float32) uint32

Float32ToUint32 float32 -> uint32

func Float64ToByte

func Float64ToByte(f float64) []byte

Float64ToByte float64 -> []byte

func Float64ToUint64

func Float64ToUint64(f float64) uint64

Float64ToUint64 float64 -> uint64

func Get16MD5Encode

func Get16MD5Encode(data string) string

Get16MD5Encode 返回一个16位md5加密后的字符串

func GetAliYunOSSClient

func GetAliYunOSSClient(tag string) *oss.Bucket

func GetAllFile

func GetAllFile(pathname string) ([]string, error)

GetAllFile 获取目录下的所有文件

func GetDate

func GetDate() string

func GetMD5Encode

func GetMD5Encode(data string) string

GetMD5Encode 获取Md5编码

func GetMinioClient

func GetMinioClient(tag string) *minio.Client

func GetMongoDBConn

func GetMongoDBConn(tag string) *mongo.Database

func GetMysqlConn

func GetMysqlConn(tag string) *gorm.DB

func GetPgsqlConn

func GetPgsqlConn(tag string) *sql.DB

func GetRedisConn

func GetRedisConn(tag string) *redis.Client

func GetTencentCOSClient

func GetTencentCOSClient(tag string) *cos.Client

func GetUUID

func GetUUID() string

func HexToInt

func HexToInt(s string) int

HexToInt hex -> int

func HexToInt64

func HexToInt64(s string) int64

HexToInt64 hex -> int

func ID

func ID() int64

func ID64

func ID64() (int64, error)

func IDMd5

func IDMd5() string

func IDStr

func IDStr() string

func Info

func Info(args ...interface{})

func InfoF

func InfoF(format string, args ...interface{})

func InfoFTimes

func InfoFTimes(times int, format string, args ...interface{})

InfoFTimes times 意思是打印第几级函数调用

func InfoTimes

func InfoTimes(times int, args ...interface{})

InfoTimes times 意思是打印第几级函数调用

func InitConf

func InitConf(path string)

InitConf 初始化读取配置文件并连接各个配置,输入配置文件路径,路径是当前工作目录的相对路径

func Int64ToByte

func Int64ToByte(i int64) []byte

Int64ToByte int64 -> []byte

func Int64ToHex

func Int64ToHex(i int64) string

Int64ToHex int64 -> hex

func Int64ToStr

func Int64ToStr(i int64) string

Int64ToStr int64 -> string

func IntToByte

func IntToByte(i int) []byte

IntToByte int -> []byte

func IntToHex

func IntToHex(i int) string

IntToHex int -> hex

func IsUtf8

func IsUtf8(buf []byte) bool

func JsonToMap

func JsonToMap(str string) (map[string]interface{}, error)

JsonToMap json -> map

func MD5

func MD5(str string) string

MD5 MD5

func MapStrToAny

func MapStrToAny(m map[string]string) map[string]interface{}

MapStrToAny map[string]string -> map[string]interface{}

func MapToJson

func MapToJson(m interface{}) (string, error)

MapToJson map -> json

func MinioCreateBucket

func MinioCreateBucket(client *minio.Client, ctx context.Context, bucketName string) error

MinioCreateBucket 创建存储桶

func MinioDeleteBucket

func MinioDeleteBucket(client *minio.Client, ctx context.Context, bucketName string) error

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

func MinioListObjects(client *minio.Client, ctx context.Context, bucketName string) error

MinioListObjects 列出存储桶中的对象

func MinioUploadFile

func MinioUploadFile(client *minio.Client, ctx context.Context, bucketName, objectName, filePath, contentType string) error

MinioUploadFile 上传文件

func NowTimestampStr

func NowTimestampStr() string

func P2E

func P2E()

P2E panic -> error

func Panic

func Panic(args ...interface{})

func PanicToError

func PanicToError(fn func()) (err error)

PanicToError panic -> error

func PathMkdir

func PathMkdir(path string)

PathMkdir 目录不存在则创建

func Print

func Print(args ...interface{})

func PrintF

func PrintF(format string, args ...interface{})

func RandomIntCaptcha

func RandomIntCaptcha(captchaLen int) string

RandomIntCaptcha 生成 captchaLen 位随机数,理论上会重复

func SetAppName

func SetAppName(name string)

SetAppName 设置项目名称

func SetLogFile

func SetLogFile(dir, name string, maxDay int)

SetLogFile 设置日志文件名称, 文件名称可含路径(绝对或相对)

func SetOutService

func SetOutService(ip string, port int)

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 SliceMax

func SliceMax[V number](a []V) V

func SliceMin

func SliceMin[V number](a []V) 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 StrNumToFloat32

func StrNumToFloat32(str string) float32

StrNumToFloat32 string -> float32

func StrNumToFloat64

func StrNumToFloat64(str string) float64

StrNumToFloat64 string -> float64

func StrNumToInt

func StrNumToInt(str string) int

StrNumToInt string -> int

func StrNumToInt32

func StrNumToInt32(str string) int32

StrNumToInt32 string -> int32

func StrNumToInt64

func StrNumToInt64(str string) int64

StrNumToInt64 string -> int64

func StrToByte

func StrToByte(s string) []byte

StrToByte string -> []byte

func StructToMap

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

StructToMap struct -> map[string]interface{}

func StructToMapV2

func StructToMapV2(obj interface{}, hasValue bool) (map[string]interface{}, error)

StructToMapV2 Struct -> map hasValue=true表示字段值不管是否存在都转换成map hasValue=false表示字段为不为空或者不为0则转换成map

func StructToMapV3

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

StructToMapV3 struct -> map

func TencentCOSCheckIsExist

func TencentCOSCheckIsExist(cosClient *cos.Client, keyName string) bool

TencentCOSCheckIsExist 检查文件是否存在

func TimeHM

func TimeHM(t time.Time) string

func TimeStr2Unix

func TimeStr2Unix(timeStr string) int64

func TimeStr2UnixByLayOut

func TimeStr2UnixByLayOut(layout, timeStr string) int64

func TimeToYMD

func TimeToYMD(t time.Time) string

func TimeToYMDHMS

func TimeToYMDHMS(t time.Time) string

func TimeYMDCN

func TimeYMDCN(t time.Time) string

func Timestamp2Time

func Timestamp2Time(timestamp int64) time.Time

func Timestamp2Week

func Timestamp2Week(timestamp int64) string

func TimestampSubDay

func TimestampSubDay(timestamp int64) int64

func Uint8ToStr

func Uint8ToStr(bs []uint8) string

Uint8ToStr []uint8 -> string

func Warn

func Warn(args ...interface{})

func WarnF

func WarnF(format string, args ...interface{})

func WarnFTimes

func WarnFTimes(times int, format string, args ...interface{})

func WarnTimes

func WarnTimes(times int, args ...interface{})

Types

type AliYunOSS

type AliYunOSS struct {
	Tag             string `yaml:"tag"`      // 标记,通过标记获得连接
	Endpoint        string `yaml:"endpoint"` // OSS访问域名,如:oss-cn-hangzhou.aliyuncs.com
	AccessKeyId     string `yaml:"accessKeyId"`
	AccessKeySecret string `yaml:"accessKeySecret"`
	BucketName      string `yaml:"bucketName"`
}

type FileInfo

type FileInfo struct {
	Name    string
	ModTime time.Time
	Size    int64
}

type GormLogger

type GormLogger struct {
	SlowThreshold time.Duration
}

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 (*GormLogger) Trace

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLogger) Warn

func (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

type IdWorker

type IdWorker struct {
	// contains filtered or unexported fields
}

IdWorker 雪花Id

func (*IdWorker) InitIdWorker

func (idw *IdWorker) InitIdWorker(workerId, datacenterId int64) error

func (*IdWorker) NextId

func (idw *IdWorker) NextId() (int64, error)

NextId 返回一个唯一的 INT64 ID

type Level

type Level int

type MinIOConf

type MinIOConf struct {
	Tag             string `yaml:"tag"`             // 标记,通过标记获得连接
	Endpoint        string `yaml:"endpoint"`        // MinIO 服务器地址
	AccessKeyId     string `yaml:"accessKeyId"`     // 访问密钥 ID
	AccessKeySecret string `yaml:"accessKeySecret"` // 秘密访问密钥
	UseSSL          bool   `yaml:"useSSL"`          // 是否使用 SSL   true/false
}

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

Jump to

Keyboard shortcuts

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