cmn

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 76 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FMT_MM_DD                   = "MM-dd"
	FMT_YYYYMM                  = "yyyyMM"
	FMT_YYYY_MM                 = "yyyy-MM"
	FMT_YYYY_MM_DD              = "yyyy-MM-dd"
	FMT_YYYYMMDD                = "yyyyMMdd"
	FMT_YYYYMMDDHHMMSS          = "yyyyMMddHHmmss"
	FMT_YYYYMMDDHHMM            = "yyyyMMddHHmm"
	FMT_YYYYMMDDHH              = "yyyyMMddHH"
	FMT_YYMMDDHHMM              = "yyMMddHHmm"
	FMT_MM_DD_HH_MM             = "MM-dd HH:mm"
	FMT_MM_DD_HH_MM_SS          = "MM-dd HH:mm:ss"
	FMT_YYYY_MM_DD_HH_MM        = "yyyy-MM-dd HH:mm"
	FMT_YYYY_MM_DD_HH_MM_SS     = "yyyy-MM-dd HH:mm:ss"
	FMT_YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss.SSS"

	FMT_MM_DD_EN                   = "MM/dd"
	FMT_YYYY_MM_EN                 = "yyyy/MM"
	FMT_YYYY_MM_DD_EN              = "yyyy/MM/dd"
	FMT_MM_DD_HH_MM_EN             = "MM/dd HH:mm"
	FMT_MM_DD_HH_MM_SS_EN          = "MM/dd HH:mm:ss"
	FMT_YYYY_MM_DD_HH_MM_EN        = "yyyy/MM/dd HH:mm"
	FMT_YYYY_MM_DD_HH_MM_SS_EN     = "yyyy/MM/dd HH:mm:ss"
	FMT_YYYY_MM_DD_HH_MM_SS_SSS_EN = "yyyy/MM/dd HH:mm:ss.SSS"

	FMT_MM_DD_CN               = "MM月dd日"
	FMT_YYYY_MM_CN             = "yyyy年MM月"
	FMT_YYYY_MM_DD_CN          = "yyyy年MM月dd日"
	FMT_MM_DD_HH_MM_CN         = "MM月dd日 HH:mm"
	FMT_MM_DD_HH_MM_SS_CN      = "MM月dd日 HH:mm:ss"
	FMT_YYYY_MM_DD_HH_MM_CN    = "yyyy年MM月dd日 HH:mm"
	FMT_YYYY_MM_DD_HH_MM_SS_CN = "yyyy年MM月dd日 HH:mm:ss"

	FMT_HH_MM       = "HH:mm"
	FMT_HH_MM_SS    = "HH:mm:ss"
	FMT_HH_MM_SS_MS = "HH:mm:ss.SSS"
)

日期格式模板

Variables

This section is empty.

Functions

func AbsInt

func AbsInt(a int) int

绝对值

func AbsInt64

func AbsInt64(a int64) int64

绝对值

func AmountToCny

func AmountToCny(val string) string

金额数字转人民币大写(最大支持千万亿,小数只精确到分,分以下舍去。超过支持的最大值时原样返回不转换)

1234567890123456.789 -> 壹仟贰佰叁拾肆万伍仟陆佰柒拾捌亿玖仟零壹拾贰万叁仟肆佰伍拾陆元柒角捌分 -1234567890123456.78 -> 负壹仟贰佰叁拾肆万伍仟陆佰柒拾捌亿玖仟零壹拾贰万叁仟肆佰伍拾陆元柒角捌分 12345.7 -> 壹万贰仟叁佰肆拾伍元柒角整 12345.0 -> 壹万贰仟叁佰肆拾伍元整 12345 -> 壹万贰仟叁佰肆拾伍元整 9002300040 -> 玖拾亿零贰佰叁拾万零肆拾元整 9002300043.0 -> 玖拾亿零贰佰叁拾万零肆拾叁元整 12345678901234567.781 -> 12345678901234567.781

func Base64

func Base64(bts []byte) string

Base64编码(同Base64Encode)

func Base64Decode

func Base64Decode(str string) ([]byte, error)

Base64解码

func Base64Encode

func Base64Encode(bts []byte) string

Base64编码

func BoolToString

func BoolToString(b bool) string

bool 转 string

func BytesToReader added in v0.7.6

func BytesToReader(bts []byte) io.Reader

[]byte 转 io.Reader

func BytesToString

func BytesToString(b []byte) string

[]byte 转 string

func BytesToUint32

func BytesToUint32(bytes []byte) uint32

[]byte 转 uint32

func BytesToUint64

func BytesToUint64(bytes []byte) uint64

[]byte 转 uint64

func CamelToUnderline

func CamelToUnderline(str string) string

驼峰转全小写下划线(已含下划线时直接转小写)

func Compress

func Compress(srcBytes []byte) []byte

使用snappy算法压缩(压缩速度快,占用资源少,压缩比适当,重复多则压缩比大,适用于重复较多的文本压缩)

func Contains

func Contains(str string, substr string) bool

判断是否包含(区分大小写)

func ContainsIngoreCase

func ContainsIngoreCase(str string, substr string) bool

判断是否包含(忽略大小写)

func CopyDir added in v0.7.9

func CopyDir(srcDir, dstDir string) error

复制目录(源目录中的文件和子目录,复制到目标目录,目标目录不存在时自动创建)

func CopyFile

func CopyFile(srcFilePath string, dstFilePath string) error

复制文件

func CreateShortcutFile added in v0.7.9

func CreateShortcutFile(targetFile string, shortcutLnkFile string) error

生成指定文件的快捷文件

func DbFieldName

func DbFieldName(name string) string

转数据库字段名(驼峰转下划线小写)

func DbTableName

func DbTableName(name string) string

转数据库表名(驼峰转下划线小写)

func Debug

func Debug(v ...any)

打印Debug级别日志

func DecodeRsa

func DecodeRsa(str string, priKey string) (string, error)

按Base64解码字符串后使用私钥进行RSA解密

func DecodeRsaByPriFile

func DecodeRsaByPriFile(str string, pubKeyFileName string) (string, error)

按Base64解码字符串后使用私钥文件进行RSA解密

func DecodeRsaBytes

func DecodeRsaBytes(cipherText, privateKey []byte) ([]byte, error)

使用秘钥解密

func DecodeRsaBytesByPriFile

func DecodeRsaBytesByPriFile(data []byte, privateKeyFileName string) ([]byte, error)

使用私钥文件进行RSA解密

func EncodeRsa

func EncodeRsa(str string, pubKey string) (string, error)

使用公钥进行RSA加密后按Base64编码字符串

func EncodeRsaByPubFile

func EncodeRsaByPubFile(str string, pubKeyFileName string) (string, error)

使用公钥文件进行RSA加密后按Base64编码字符串

func EncodeRsaBytes

func EncodeRsaBytes(data []byte, publicKey []byte) ([]byte, error)

使用公钥加密

func EncodeRsaBytesByPubFile

func EncodeRsaBytesByPubFile(data []byte, pubKeyFileName string) ([]byte, error)

使用公钥文件进行RSA加密

func Endwiths

func Endwiths(str string, endstr string) bool

判断是否指定后缀

func EqualsIngoreCase

func EqualsIngoreCase(str1 string, str2 string) bool

判断是否相同(忽略大小写)

func Error

func Error(v ...any)

打印Error级别日志

func ExecCmd

func ExecCmd(command string) (stdout, stderr string, err error)

执行命令(Windows时为cmd,否则是bash)

func ExecTime

func ExecTime(fn func()) int64

计算函数执行时间(毫秒)

func FasthttpPostJson

func FasthttpPostJson(url string, jsondata string, headers ...string) ([]byte, error)

使用Fasthttp进行Post请求,固定Content-Type:application/json;charset=UTF-8,其他自定义headers格式为 K:V

func Fatal

func Fatal(v ...any)

打印Fatal级别日志

func Fatalln

func Fatalln(v ...any)

打印Fatal级别日志,然后退出

func FileExtName

func FileExtName(name string) string

取文件扩展名,如“.txt”

func FileName

func FileName(name string) string

取文件名,如“abc.txt”

func Float64ToCny

func Float64ToCny(val float64) string

金额数字转人民币大写(百万亿级别正常,超过范围可能转数字字符串出现进位)

func Float64ToInt64

func Float64ToInt64(f float64) int64

float64 转 int64

func Float64ToString

func Float64ToString(num float64) string

float64 转 string (注:千万亿大数时可能进位,不绝对)

func Float64ToStringRoundDown

func Float64ToStringRoundDown(num float64, digit int32) string

float64 转 string,保留指定位数小数,后续小数位舍去

Float64ToStringRoundDown(1234567890123456,2) -> 1234567890123456.00 Float64ToStringRoundDown(999999999999.999,2) -> 999999999999.99

func FormatAmountRound

func FormatAmountRound(num float64, digit int32) string

float64 转 string,整数部分3位一撇,四舍五入保留或补足指定位数小数

func FormatDate

func FormatDate(date time.Time, fmt DateFormat) string

格式化日期

func FormatRound

func FormatRound(num float64, digit int32) string

float64 转 string,四舍五入保留或补足指定位数小数

func FormatSystemDate

func FormatSystemDate(fmt DateFormat) string

格式化系统日期

func GbkToUtf8

func GbkToUtf8(gbk []byte) []byte

gbk转utf8

func GenerateRSAKey

func GenerateRSAKey(keySize int) (privateKey []byte, publicKey []byte, err error)

创建秘钥

func GenerateRsaKey

func GenerateRsaKey() error

当前目录下创建2048位的秘钥文件"rsa_private.pem、rsa_public.pem"

func GenerateRsaKeyFile

func GenerateRsaKeyFile(keySize int, priKeyFile, pubKeyFile string) error

创建秘钥文件(keySize通常是1024、2048、4096)

func GetCityByIp

func GetCityByIp(ip string) string

获取ip所属城市

func GetEnvBool

func GetEnvBool(name string, defaultValue ...bool) bool

取环境变量

func GetEnvInt

func GetEnvInt(name string, defaultValue ...int) int

取环境变量

func GetEnvStr

func GetEnvStr(name string, defaultValue ...string) string

取环境变量

func GetHtmlText

func GetHtmlText(strHtml string) string

对html进行分词前的文本提取(提取html中的文本并进行反转义)

func GetLocalHostName

func GetLocalHostName() string

取本机名

func GetLocalIp

func GetLocalIp() string

取本机IP地址(IPv4)

func GetTypeOfStructPointer

func GetTypeOfStructPointer(structPointer any) (reflect.Type, error)

反射解析出结构体类型 参数仅接受:结构体对象指针

func GetTypeOfStructSlicePointer

func GetTypeOfStructSlicePointer(structSlicePointer any) (reflect.Type, error)

反射解析出结构体类型 参数仅接受:结构体对象切片指针

func GetUserHomeDir added in v0.7.9

func GetUserHomeDir() string

func GetUserStartupDir added in v0.7.9

func GetUserStartupDir() string

func GetYyyymmdd

func GetYyyymmdd(addDays int) string

当前日期加减天数后的yyyymmdd格式

func Gzip

func Gzip(srcFile string, gzipFile string) error

指定文件压缩为gzip文件(文件名不支持中文)

func Hash

func Hash(str string) uint32

哈希码

func HashCode

func HashCode(bts []byte) uint32

哈希码

func HashMod

func HashMod(str string, mod uint32) uint32

字符串哈希处理后取模(余数),返回值最大不超过mod值

func HexToRgb

func HexToRgb(hex string) (rgb []int)

颜色转换(HEX => RGB)

rgb := HexToRgb("ccc") // rgb: [204 204 204]
rgb := HexToRgb("aabbcc") // rgb: [170 187 204]
rgb := HexToRgb("#aabbcc") // rgb: [170 187 204]
rgb := HexToRgb("0xad99c0") // rgb: [170 187 204]

func HostsAddDomain added in v0.7.8

func HostsAddDomain(ip string, domain string) error

在 C:/Windows/System32/drivers/etc/hosts 中添加指定映射

func HttpDownload added in v0.7.9

func HttpDownload(url, saveAsPathFile string) error

下载文件

func HttpGetJson

func HttpGetJson(url string, headers ...string) ([]byte, error)

使用标准包进行Get请求,固定Content-Type:application/json;charset=UTF-8,其他自定义headers格式为 K:V

func HttpPostForm

func HttpPostForm(url string, formMap map[string]string, headers ...string) ([]byte, error)

使用标准包进行Post请求,固定Content-Type:application/x-www-form-urlencoded,其他自定义headers格式为 K:V

func HttpPostJson

func HttpPostJson(url string, jsondata string, headers ...string) ([]byte, error)

使用标准包进行Post请求,固定Content-Type:application/json;charset=UTF-8,其他自定义headers格式为 K:V

func HttpUploadFile added in v0.7.8

func HttpUploadFile(url string, filePath string, headers ...string) ([]byte, error)

使用标准包进行Post请求,固定Content-Type:multipart/form-data,其他自定义headers格式为 K:V

func ImgBlur

func ImgBlur(srcFile string, distFile string, sigma float64) error

高斯模糊处理 srcFile:处理前文件 distFile:处理后文件 sigma:模糊比例(通常可设定为5)

func ImgBmpToJpg

func ImgBmpToJpg(buf []byte, o *jpeg.Options) []byte

bmp文件转jpg文件

func ImgCompress

func ImgCompress(buf []byte, maxWidth uint, maxHeight uint, o *jpeg.Options) []byte

图片有损压缩 maxWidth:压缩后的最大宽度 maxHeight:压缩后的最大高度 o:压缩比例(nil时为默认80%)

func ImgResize

func ImgResize(srcFile string, distFile string, maxWidth uint, maxHeight uint, o *jpeg.Options)

图片有损压缩(压缩失败时原样保存至目标文件) srcFile:压缩前文件 distFile:压缩后文件 maxWidth:压缩后的最大宽度 maxHeight:压缩后的最大高度 o:压缩比例(nil时为默认80%)

func IndexOf

func IndexOf(str string, substr string) int

查找文字下标

func Info

func Info(v ...any)

打印Info级别日志

func Int64ToBytes

func Int64ToBytes(i int64) []byte

int64 转 []byte

func Int64ToString

func Int64ToString(i int64) string

int64 转 string

func IntToBytes

func IntToBytes(intNum int) []byte

int 转 []byte

func IntToExcelColumn

func IntToExcelColumn(iCol int) string

int 转 Excel列字母 (如 1 -> A,2->B )

func IntToString

func IntToString(i int) string

int 转 string

func IsAlpha

func IsAlpha(s string) bool

判断是否半角字母

func IsAlphaDigit

func IsAlphaDigit(s string) bool

判断是否半角英数(不含符号)

func IsAlpine

func IsAlpine() bool

是否alpine系统

func IsBlank

func IsBlank(str string) bool

判断是否空白

func IsDigit

func IsDigit(s string) bool

判断是否半角数字

func IsEmail

func IsEmail(str string) bool

判断是否Email地址

func IsExistDir

func IsExistDir(dir string) bool

判断文件夹是否存在

func IsExistFile

func IsExistFile(file string) bool

判断文件是否存在

func IsFullWidth

func IsFullWidth(s string) bool

判断是否全部都是全角字符

func IsHalfWidth

func IsHalfWidth(s string) bool

判断是否全部都是半角字符

func IsIPv4

func IsIPv4(str string) bool

判断是否IPv4地址

func IsIPv6

func IsIPv6(str string) bool

判断是否IPv6地址

func IsIdCard

func IsIdCard(idCard string) bool

判断是否身份证号码,若按标准校验失败也返回false

func IsIp

func IsIp(str string) bool

判断是否IP地址

func IsLinux

func IsLinux() bool

是否Linux系统

func IsMac

func IsMac() bool

是否Mac系统

func IsMobile

func IsMobile(phone string) bool

判断是否手机号

func IsNumber

func IsNumber(s string) bool

判断是否数值(123、123.456、-123.456都认为是数值)

func IsTypeOfArray

func IsTypeOfArray(v any) bool

判断类型是否为array

func IsTypeOfBool

func IsTypeOfBool(v any) bool

判断类型是否为bool

func IsTypeOfChan

func IsTypeOfChan(v any) bool

判断类型是否为chan

func IsTypeOfComplex128

func IsTypeOfComplex128(v any) bool

判断类型是否为complex128

func IsTypeOfComplex64

func IsTypeOfComplex64(v any) bool

判断类型是否为complex64

func IsTypeOfFloat32

func IsTypeOfFloat32(v any) bool

判断类型是否为float32

func IsTypeOfFloat64

func IsTypeOfFloat64(v any) bool

判断类型是否为float64

func IsTypeOfFunc

func IsTypeOfFunc(v any) bool

判断类型是否为func

func IsTypeOfInt

func IsTypeOfInt(v any) bool

判断类型是否为int

func IsTypeOfInt16

func IsTypeOfInt16(v any) bool

判断类型是否为int16

func IsTypeOfInt32

func IsTypeOfInt32(v any) bool

判断类型是否为int32

func IsTypeOfInt64

func IsTypeOfInt64(v any) bool

判断类型是否为int64

func IsTypeOfInt8

func IsTypeOfInt8(v any) bool

判断类型是否为int8

func IsTypeOfInterface

func IsTypeOfInterface(v any) bool

判断类型是否为interface

func IsTypeOfMap

func IsTypeOfMap(v any) bool

判断类型是否为map

func IsTypeOfPointer

func IsTypeOfPointer(v any) bool

判断类型是否为pointer

func IsTypeOfSlice

func IsTypeOfSlice(v any) bool

判断类型是否为slice

func IsTypeOfString

func IsTypeOfString(v any) bool

判断类型是否为string

func IsTypeOfStruct

func IsTypeOfStruct(v any) bool

判断类型是否为struct

func IsTypeOfUint

func IsTypeOfUint(v any) bool

判断类型是否为uint

func IsTypeOfUint16

func IsTypeOfUint16(v any) bool

判断类型是否为uint16

func IsTypeOfUint32

func IsTypeOfUint32(v any) bool

判断类型是否为uint32

func IsTypeOfUint64

func IsTypeOfUint64(v any) bool

判断类型是否为uint64

func IsTypeOfUint8

func IsTypeOfUint8(v any) bool

判断类型是否为uint8

func IsTypeOfUintptr

func IsTypeOfUintptr(v any) bool

判断类型是否为uintptr

func IsTypeOfUnsafePointer

func IsTypeOfUnsafePointer(v any) bool

判断类型是否为unsafePointer

func IsWin

func IsWin() bool

是否Windows系统

func Join

func Join(elems []string, sep string) string

字符串数组拼接为字符串

func Left

func Left(str string, length int) string

取左文字

func Len

func Len(str string) int

按文字计算字符串长度

func MapToStruct

func MapToStruct(mapFrom map[string]any, objPtrTo any)

func Md5

func Md5(bts []byte) string

MD5

func Md5File

func Md5File(pathfile string) string

文件MD5(文件读取失败时返回空串的MD5)

func MeasureCPU

func MeasureCPU() (physicalCount int, logicalCount int, usePercent float64)

检测CPU

func MeasureDisk

func MeasureDisk() (total uint64, used uint64, free uint64, usePercent float64)

检测磁盘(当前盘)

func MeasureDisks

func MeasureDisks() []*disk.UsageStat

检测所有磁盘

func MeasureHost

func MeasureHost() (*host.InfoStat, error)

检测主机信息

func MeasureMemory

func MeasureMemory() (total uint64, used uint64, free uint64, usePercent float64)

检测内存

func MeasureSummary

func MeasureSummary() (cpuUsedPercent float64, memUsedPercent float64, diskUsedPercent float64)

检测CPU、内存、磁盘使用占比

func MeasureSwap

func MeasureSwap() (total uint64, used uint64, free uint64, usePercent float64)

检测虚拟内存

func OfMap added in v0.7.6

func OfMap(kvs ...any) map[string]any

构建Map 如:OfMap("n1",1, "n2","v2", "n3",nil)

func OnExit

func OnExit(fnExit func())

注册退出处理函数,在接收到SIGTERM或SIGINT信号时执行

func PadLeft

func PadLeft(str string, pad string, length int) string

左补足

func PadRight

func PadRight(str string, pad string, length int) string

右补足

func ParseDate

func ParseDate(date string, fmt DateFormat) (time.Time, error)

指定格式的字符串转日期

func ParseStructFieldType

func ParseStructFieldType(structType reflect.Type) map[string]string

func ParseStructType

func ParseStructType(obj any) (reflect.Type, error)

反射解析出结构体类型 参数仅接受:结构体对象、结构体对象指针、结构体对象切片、结构体对象切片指针

func PathSeparator

func PathSeparator() string

路径分隔符

func Println

func Println(v ...any)

打印日志

func RandomInt

func RandomInt(min, max int) int

随机数

func RandomString

func RandomString(length int) string

随机半角英数字符串

func RandomUint32

func RandomUint32() uint32

随机数

func RandomUint64

func RandomUint64() uint64

随机数

func ReadFileBytes

func ReadFileBytes(filename string) ([]byte, error)

一次性读文件(适用于小文件)

func ReadFileString

func ReadFileString(filename string) (string, error)

一次性读文件(适用于小文件)

func ReaderToBytes added in v0.7.6

func ReaderToBytes(ioReader io.Reader) []byte

io.Reader 转 []byte

func RemoveAllFile

func RemoveAllFile(pathorfile string) error

删除文件或目录(含全部子目录文件)

func Repeat

func Repeat(str string, count int) string

重复

func Replace

func Replace(str string, old string, new string, n int) string

替换

func ReplaceAll

func ReplaceAll(str string, old string, new string) string

全部替换

func ReplaceAllSpace added in v0.7.8

func ReplaceAllSpace(str string, new string) string

全部替换连续的空白

func Retry

func Retry(callback func() error, retryTimes int, duration time.Duration) (err error)

执行回调函数,错误时重试

func Reverse

func Reverse(str string) string

反转

func RgbToHex

func RgbToHex(r int, g int, b int) string

颜色转换(RGB => HEX)

hex := RgbToHex(170, 187, 204) // hex: "#aabbcc"
func Right(str string, length int) string

取右文字

func Round

func Round(num float64, digit int32) float64

四舍五入保留指定位数(0-16)的小数

func Round1

func Round1(num float64) float64

四舍五入保留1位小数

func Round2

func Round2(num float64) float64

四舍五入保留2位小数

func RoundDown

func RoundDown(num float64, digit int32) float64

保留指定位数(0-16)的小数(后面小数舍去)

func SetLogCenterClient

func SetLogCenterClient(glcClient *GLogCenterClient)

设定GLC日志中心客户端

func SetLogLevel

func SetLogLevel(level string)

设定日志级别(trace/debug/info/warn/error/fatal)

func Split

func Split(str string, sep string) []string

字符串切割

func SshCmd

func SshCmd(host string, port string, user string, password string, cmd ...string) (string, error)

远程ssh执行命令

func Startwiths

func Startwiths(str string, startstr string) bool

判断是否指定前缀

func String2Float64

func String2Float64(s string, defaultVal float64) float64

string 转 float64

func StringToBool

func StringToBool(s string, defaultVal bool) bool

string 转 bool

func StringToBytes

func StringToBytes(s string) []byte

string 转 []byte

func StringToInt

func StringToInt(s string, defaultVal int) int

string 转 int

func StringToInt64

func StringToInt64(s string, defaultVal int64) int64

string 转 int64

func StringToUint32

func StringToUint32(s string, defaultVal uint32) uint32

字符串(10进制无符号整数形式)转uint32,超过uint32最大值会丢失精度,转换失败时返回默认值

func StructToMap

func StructToMap(obj any) map[string]any

func SubString

func SubString(str string, start int, end int) string

按文字截取字符串

func TarDir

func TarDir(directory string, tarfilename string) error

打包指定目录为指定的tar文件

func Titlelize

func Titlelize(str string) string

首字母转大写

func ToLower

func ToLower(str string) string

转小写

func ToUpper

func ToUpper(str string) string

转大写

func Today

func Today() string

当日的yyyymmdd格式

func Trace

func Trace(v ...any)

打印Trace级别日志

func Trim

func Trim(str string) string

去除两边空格

func TrimPrefix

func TrimPrefix(str string, prefix string) string

去除左前缀

func ULID

func ULID() string

ULID

ULID常作为UUID的替代方案,固定26位长度(10位时间戳+16位随机数),适用于数据库ID。 主要特点:毫秒精度有序(仅同一毫秒内无序)、无特殊字符

func Uint16ToBytes

func Uint16ToBytes(num uint16) []byte

uint16 转 []byte

func Uint32ToBytes

func Uint32ToBytes(num uint32) []byte

uint32 转 []byte

func Uint32ToString

func Uint32ToString(num uint32) string

uint32 转 string

func Uint64ToBytes

func Uint64ToBytes(num uint64) []byte

uint64 转 []byte

func Uint64ToString

func Uint64ToString(i uint64) string

uint64 转 string

func UnCompress

func UnCompress(snappyEncodedBytes []byte) []byte

解压snappy算法压缩的结果(若解压失败返回原参数)

func UnGzip

func UnGzip(gzipPathFile string, destPath string) error

解压gzip文件到指定目录

func UnTar

func UnTar(tarFile string, dist string) error

把tar文件解压到指定目录中

func UnZip

func UnZip(zipFile string, destPath string) error

解压指定zip文件

func UnderlineToCamel

func UnderlineToCamel(str string) string

下划线转驼峰(无下划线时不转换)

func Unique

func Unique(strs []string) []string

字符串去重

func Utf8ToGbk

func Utf8ToGbk(utf8 []byte) []byte

utf8转gbk

func Warn

func Warn(v ...any)

打印Warn级别日志

func WriteFileBytes

func WriteFileBytes(filename string, data []byte) error

写文件(指定目录不存在时先创建,不含目录时存当前目录)

func WriteFileString

func WriteFileString(filename string, content string) error

写文件(指定目录不存在时先创建,不含目录时存当前目录)

func Zip

func Zip(srcFileOrPath string, zipPathFile string) error

压缩指定目录为指定的zip文件

Types

type AesEcb

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

对称加密结构体

func NewAesEcb

func NewAesEcb(secret string) *AesEcb

创建指定密码的对称加密对象

func (*AesEcb) Decode

func (a *AesEcb) Decode(src string) (string, error)

字符串解密

func (*AesEcb) DecodeBytes

func (a *AesEcb) DecodeBytes(src []byte, secret []byte) ([]byte, error)

字节数组解密

func (*AesEcb) Encode

func (a *AesEcb) Encode(src string) (string, error)

字符串加密

func (*AesEcb) EncodeBytes

func (a *AesEcb) EncodeBytes(src []byte, secret []byte) ([]byte, error)

字节数组加密

type BaiduOcr

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

func NewBaiduOcr

func NewBaiduOcr(apiKey string, secretKey string) *BaiduOcr

创建百度OCR对象(参数apiKey和secretKey在百度注册应用后获取)

func (*BaiduOcr) QuotaInvoice

func (b *BaiduOcr) QuotaInvoice(filebytes []byte, isPdf bool) (string, error)

定额发票识别,支持png/jpeg/jpg/bpm/pdf类型(返回JSON识别结果)

支持对各类定额发票的发票代码、发票号码、金额、发票所在地、发票金额小写、省、市7个关键字段进行结构化识别

func (*BaiduOcr) VatInvoice

func (b *BaiduOcr) VatInvoice(filebytes []byte, isPdf bool) (string, error)

增值税发票识别,支持png/jpeg/jpg/bpm/pdf类型(返回JSON识别结果)

支持对增值税普票、专票、卷票、电子发票的所有字段进行结构化识别, 包括发票基本信息、销售方及购买方信息、商品信息、价税信息等,其中四要素识别准确率超过 99.9%; 同时,支持对增值税卷票的 21 个关键字段进行识别,包括发票类型、发票代码、发票号码、机打号码、 机器编号、收款人、销售方名称、销售方纳税人识别号、开票日期、购买方名称、购买方纳税人识别号、 项目、单价、数量、金额、税额、合计金额(小写)、合计金额(大写)、校验码、省、市,四要素平均识别准确率可达95%以上。

type DateFormat

type DateFormat string

日期格式,使用常量 FMT_XXX

type DbHandle

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

数据库控制器

func NewDbHandle

func NewDbHandle(opt ...*DbOption) *DbHandle

新建数据库控制器

func (*DbHandle) BeginTransaction

func (d *DbHandle) BeginTransaction()

开启事务,出错时panic

func (*DbHandle) Commit

func (d *DbHandle) Commit() error

提交事务,失败时返回错误

func (*DbHandle) Count

func (d *DbHandle) Count(sql string, params ...any) int

查找件数,出错时panic

func (*DbHandle) Delete

func (d *DbHandle) Delete(deleter *SqlDeleter) int64

删除记录,出错时panic

func (*DbHandle) EndTransaction

func (d *DbHandle) EndTransaction() error

结束事务(未曾出错时提交,否则回滚),失败时返回错误

func (*DbHandle) Err

func (d *DbHandle) Err() error

取错误信息

func (*DbHandle) Execute

func (d *DbHandle) Execute(sql string, params ...any) int64

执行SQL(开启事务时自动在事务内执行),出错时panic

func (*DbHandle) FindFloat64

func (d *DbHandle) FindFloat64(sql string, params ...any) float64

查找单记录的单个字段值,出错时panic

func (*DbHandle) FindInt

func (d *DbHandle) FindInt(sql string, params ...any) int

查找单记录的单个字段值,出错时panic

func (*DbHandle) FindList

func (d *DbHandle) FindList(structSlicePtr any, sql string, params ...any)

查找记录并存入参数所指切片,出错时panic 参数structSlicePtr必须是结构体对象切片的指针

func (*DbHandle) FindMap

func (d *DbHandle) FindMap(entity any, sql string, params ...any) map[string]any

查找一条记录,返回Map或无数据时nil,出错时panic 参数entity通常为结构体对象或其指针(仅解析用不作修改)

func (*DbHandle) FindMaps

func (d *DbHandle) FindMaps(entity any, sql string, params ...any) []map[string]any

查找返回Map切片,出错时panic 参数entity通常为结构体对象或其指针(仅解析用不作修改)

func (*DbHandle) FindOne

func (d *DbHandle) FindOne(structPtr any, sql string, params ...any) bool

查找记录并存入参数所指对象,出错时panic 参数structPtr必须是结构体对象的指针 查有数据时返回true,否则false

func (*DbHandle) FindString

func (d *DbHandle) FindString(sql string, params ...any) string

查找单记录的单个字段值,出错时panic

func (*DbHandle) FindTime

func (d *DbHandle) FindTime(sql string, params ...any) time.Time

查找单记录的单个字段值,出错时panic

func (*DbHandle) FindValue

func (d *DbHandle) FindValue(sql string, params ...any) *DbValue

查找单记录的单个字段值,出错时panic

func (*DbHandle) Insert

func (d *DbHandle) Insert(entity any) int64

插入记录,出错时panic

func (*DbHandle) IsAutoCommit added in v0.7.4

func (d *DbHandle) IsAutoCommit() bool

是否自动提交

func (*DbHandle) Rollback

func (d *DbHandle) Rollback() error

提交事务,失败时返回错误

func (*DbHandle) Update

func (d *DbHandle) Update(updater *SqlUpdater) int64

更新记录,出错时panic

type DbOption added in v0.7.3

type DbOption struct {
	AutoCommit bool // 是否自动提交
}

配置项

type DbValue

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

func (*DbValue) Float64

func (d *DbValue) Float64() float64

func (*DbValue) Int

func (d *DbValue) Int() int

func (*DbValue) Int64

func (d *DbValue) Int64() int64

func (*DbValue) RawValue

func (d *DbValue) RawValue() any

func (*DbValue) String

func (d *DbValue) String() string

func (*DbValue) Time

func (d *DbValue) Time() time.Time

type EventBus

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

事件总线结构体

func NewEventBus

func NewEventBus() *EventBus

创建事件总线(单例)

func (*EventBus) At

func (e *EventBus) At(event string, params ...any) *EventBus

触发事件

func (*EventBus) Del

func (e *EventBus) Del(event string) *EventBus

注销事件

func (*EventBus) Off

func (e *EventBus) Off(event string, delHandles ...EventHandler) *EventBus

注销事件

func (*EventBus) On

func (e *EventBus) On(event string, handle EventHandler) *EventBus

注册事件

func (*EventBus) Reset

func (e *EventBus) Reset() *EventBus

重置

type EventHandler

type EventHandler func(params ...any)

事件处理器

type FasthttpServer

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

Fasthttp服务器结构体

func NewFasthttpServer

func NewFasthttpServer(enableCors ...bool) *FasthttpServer

创建Fasthttp服务器对象

func (*FasthttpServer) BeforeRequestHandle

func (f *FasthttpServer) BeforeRequestHandle(beforeHandle GlobalBeforeRequestHandler) *FasthttpServer

注册全局前置拦截器(前置拦截器返回true时才会继续正常处理后续请求)

func (*FasthttpServer) EnableTsl added in v0.7.8

func (f *FasthttpServer) EnableTsl(certData []byte, keyData []byte) *FasthttpServer

开启TSL

func (*FasthttpServer) FinallyRequestHandle added in v0.7.11

func (f *FasthttpServer) FinallyRequestHandle(finallyHandle GlobalBeforeRequestHandler) *FasthttpServer

注册全局后置拦截器

func (*FasthttpServer) Handle

func (f *FasthttpServer) Handle(method string, path string, handle fasthttp.RequestHandler) *FasthttpServer

注册指定方法的请求控制器

func (*FasthttpServer) HandleGet

func (f *FasthttpServer) HandleGet(path string, handle fasthttp.RequestHandler) *FasthttpServer

注册GET方法的请求控制器

func (*FasthttpServer) HandleNotFound added in v0.7.10

func (f *FasthttpServer) HandleNotFound(handle fasthttp.RequestHandler) *FasthttpServer

注册NotFound的请求控制器

func (*FasthttpServer) HandlePost

func (f *FasthttpServer) HandlePost(path string, handle fasthttp.RequestHandler) *FasthttpServer

注册POST方法的请求控制器

func (*FasthttpServer) SetPort

func (f *FasthttpServer) SetPort(port string) *FasthttpServer

设定服务端口

func (*FasthttpServer) SetServer

func (f *FasthttpServer) SetServer(server *fasthttp.Server) *FasthttpServer

设定服务配置项(参数中的Handler配置项将被忽略)

func (*FasthttpServer) Shutdown added in v0.7.8

func (f *FasthttpServer) Shutdown() error

关闭服务

func (*FasthttpServer) Start

func (f *FasthttpServer) Start() error

启动服务

type GLogCenterClient

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

日志中心客户端结构体

日志中心见 https://github.com/gotoeasy/glogcenter

func NewGLogCenterClient

func NewGLogCenterClient(o *GlcOptions) *GLogCenterClient

创建日志中心客户端对象

func (*GLogCenterClient) Debug

func (g *GLogCenterClient) Debug(v ...any)

发送Debug级别日志到日志中心

func (*GLogCenterClient) DebugSys

func (g *GLogCenterClient) DebugSys(system string, v ...any)

发送Debug级别日志到日志中心

func (*GLogCenterClient) Error

func (g *GLogCenterClient) Error(v ...any)

发送Error级别日志到日志中心

func (*GLogCenterClient) ErrorSys

func (g *GLogCenterClient) ErrorSys(system string, v ...any)

发送指定系统名的Error级别日志到日志中心

func (*GLogCenterClient) Fatal

func (g *GLogCenterClient) Fatal(v ...any)

发送Fatal级别日志到日志中心

func (*GLogCenterClient) FatalSys

func (g *GLogCenterClient) FatalSys(system string, v ...any)

发送指定系统名的Fatal级别日志到日志中心

func (*GLogCenterClient) Info

func (g *GLogCenterClient) Info(v ...any)

发送Info级别日志到日志中心

func (*GLogCenterClient) InfoSys

func (g *GLogCenterClient) InfoSys(system string, v ...any)

发送指定系统名的Info级别日志到日志中心

func (*GLogCenterClient) Println

func (g *GLogCenterClient) Println(text string)

发送日志到日志中心

func (*GLogCenterClient) Trace

func (g *GLogCenterClient) Trace(v ...any)

发送Trace级别日志到日志中心

func (*GLogCenterClient) TraceSys

func (g *GLogCenterClient) TraceSys(system string, v ...any)

发送指定系统名的Trace级别日志到日志中心

func (*GLogCenterClient) Warn

func (g *GLogCenterClient) Warn(v ...any)

发送Warn级别日志到日志中心

func (*GLogCenterClient) WarnSys

func (g *GLogCenterClient) WarnSys(system string, v ...any)

发送指定系统名的Warn级别日志到日志中心

type GlcOptions

type GlcOptions struct {
	ApiUrl   string // 日志中心的添加日志接口地址
	System   string // 系统名(对应日志中心检索页面的分类栏)
	ApiKey   string // 日志中心的ApiKey
	Enable   bool   // 是否开启发送到日志中心
	LogLevel string // 日志级别(trace/debug/info/warn/error/fatal)
}

日志中心选项

type GlobalBeforeRequestHandler

type GlobalBeforeRequestHandler func(ctx *fasthttp.RequestCtx) bool

全局前置拦截器

type JWT

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

JWT结构体

func NewJWT

func NewJWT(secret string) *JWT

创建JWT对象

func (*JWT) CreateToken

func (j *JWT) CreateToken(mapKv MapString, exp time.Duration) (string, error)

创建令牌(默认HS256算法)

func (*JWT) IsExpired

func (j *JWT) IsExpired(token string) (bool, error)

判断令牌是否已过期(过期令牌不会返回error,令牌无效时将返回error)

func (*JWT) NewToken added in v0.7.5

func (j *JWT) NewToken(username string) (string, error)

创建令牌(默认HS256算法)

func (*JWT) Parse

func (j *JWT) Parse(token string) (MapString, error)

解析令牌(过期令牌不会产生错误,返回值不包含"exp"属性)

func (*JWT) RefreshToken

func (j *JWT) RefreshToken(token string, exp time.Duration) (string, error)

续签令牌(复制原令牌后创建新令牌,原令牌可以是过期令牌)

func (*JWT) Validate

func (j *JWT) Validate(token string) (MapString, error)

校验令牌(过期令牌会返回error,返回值不包含"exp"属性)

type LevelDB

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

LevelDB结构体

func NewLevelDB

func NewLevelDB(dbPath string, opt *OptionLevelDB) *LevelDB

创建LevelDB对象,参数dbPath为数据库名目录 实际每次调用都返回同一对象,opt仅首次调用时有效,opt为nil时使用默认值

func (*LevelDB) Close

func (s *LevelDB) Close()

关闭数据库

func (*LevelDB) Del

func (s *LevelDB) Del(key []byte) error

删除

func (*LevelDB) Get

func (s *LevelDB) Get(key []byte) ([]byte, error)

获取

func (*LevelDB) GetSnapshot

func (s *LevelDB) GetSnapshot() (*leveldb.Snapshot, error)

快照

func (*LevelDB) Open

func (s *LevelDB) Open() error

打开数据库

func (*LevelDB) Put

func (s *LevelDB) Put(key []byte, value []byte) error

保存

type LogDataModel

type LogDataModel struct {
	Text       string `json:"text,omitempty"`       // 【必须】日志内容,多行时仅为首行,直接显示用,是全文检索对象
	Date       string `json:"date,omitempty"`       // 日期(格式YYYY-MM-DD HH:MM:SS.SSS)
	System     string `json:"system,omitempty"`     // 系统名
	ServerName string `json:"servername,omitempty"` // 服务器名
	ServerIp   string `json:"serverip,omitempty"`   // 服务器IP
	ClientIp   string `json:"clientip,omitempty"`   // 客户端IP
	TraceId    string `json:"traceid,omitempty"`    // 跟踪ID
	LogType    string `json:"logtype,omitempty"`    // 日志类型(1:登录日志、2:操作日志)
	LogLevel   string `json:"loglevel,omitempty"`   // 日志级别
	User       string `json:"user,omitempty"`       // 用户
	Module     string `json:"module,omitempty"`     // 模块
	Operation  string `json:"action,omitempty"`     // 操作
}

日志接口数据结构体

func (*LogDataModel) ToJson

func (d *LogDataModel) ToJson() string

type Map

type Map map[string]any

值都为any类型的map

func NewMap

func NewMap() Map

创建MapString对象

func (Map) Get

func (m Map) Get(key string) any

获取

func (Map) Put

func (m Map) Put(key string, value any) Map

设定

type MapString

type MapString map[string]string

值都为string类型的map

func NewMapString

func NewMapString() MapString

创建MapString对象

func (MapString) Get

func (m MapString) Get(key string) string

获取

func (MapString) Put

func (m MapString) Put(key string, value string) MapString

设定

type Minio

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

Minio客户端结构体

func NewMinio

func NewMinio(endpoint string, username string, password string, bucket string) *Minio

func (*Minio) Download

func (m *Minio) Download(minioObjectName string, localPathFile string) error

下载文件

func (*Minio) Upload

func (m *Minio) Upload(localPathFile string, minioObjectName string) error

上传文件

type OptionLevelDB

type OptionLevelDB struct {
	// 最大空闲时间(分钟,0~240),达空闲时间后自动关闭,小于等于0时不自动关闭,默认15分钟,最长不超4小时
	MaxIdleMinute int
}

LevelDB选项

type Redis6Client

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

Redis6客户端结构体

func NewRedis6Client

func NewRedis6Client(opt *redis.Options) *Redis6Client

创建Redis6客户端对象(单机连接)

func NewRedis6ClientSentinel

func NewRedis6ClientSentinel(opt *redis.FailoverOptions) *Redis6Client

创建Redis6客户端对象(哨兵模式连接)

opt.MasterName默认为"mymaster"

func (*Redis6Client) Close

func (r *Redis6Client) Close(key string) error

关闭客户端

func (*Redis6Client) Del

func (r *Redis6Client) Del(key string) error

删除

func (*Redis6Client) Exists

func (r *Redis6Client) Exists(key string) bool

判断是否存在

func (*Redis6Client) Get

func (r *Redis6Client) Get(key string) (string, error)

获取(空时也是error,可通过err==redis.Nil判断)

func (*Redis6Client) Set

func (r *Redis6Client) Set(key string, value string, expiration time.Duration) error

设定

type SqlDeleter

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

func NewSqlDeleter

func NewSqlDeleter() *SqlDeleter

func (*SqlDeleter) And

func (d *SqlDeleter) And(column string, param any) *SqlDeleter

func (*SqlDeleter) Build

func (d *SqlDeleter) Build() (string, []any)

func (*SqlDeleter) Delete

func (d *SqlDeleter) Delete(tableName string) *SqlDeleter

func (*SqlDeleter) Eq

func (d *SqlDeleter) Eq(column string, param any) *SqlDeleter

func (*SqlDeleter) Ge

func (d *SqlDeleter) Ge(column string, param any) *SqlDeleter

func (*SqlDeleter) GetParameters

func (d *SqlDeleter) GetParameters() []any

func (*SqlDeleter) GetSql

func (d *SqlDeleter) GetSql() string

func (*SqlDeleter) Gt

func (d *SqlDeleter) Gt(column string, param any) *SqlDeleter

func (*SqlDeleter) In

func (d *SqlDeleter) In(column string, params ...any) *SqlDeleter

func (*SqlDeleter) IsNotNull

func (d *SqlDeleter) IsNotNull(column string) *SqlDeleter

func (*SqlDeleter) IsNull

func (d *SqlDeleter) IsNull(column string) *SqlDeleter

func (*SqlDeleter) Le

func (d *SqlDeleter) Le(column string, param any) *SqlDeleter

func (*SqlDeleter) LeftLike

func (d *SqlDeleter) LeftLike(column string, param string) *SqlDeleter

func (*SqlDeleter) Like

func (d *SqlDeleter) Like(column string, param string) *SqlDeleter

func (*SqlDeleter) Lt

func (d *SqlDeleter) Lt(column string, param any) *SqlDeleter

func (*SqlDeleter) NotEq

func (d *SqlDeleter) NotEq(column string, param any) *SqlDeleter

func (*SqlDeleter) NotIn

func (d *SqlDeleter) NotIn(column string, params ...any) *SqlDeleter

func (*SqlDeleter) NotLike

func (d *SqlDeleter) NotLike(column string, param string) *SqlDeleter

func (*SqlDeleter) Or

func (d *SqlDeleter) Or(column string, param any) *SqlDeleter

func (*SqlDeleter) OrEq

func (d *SqlDeleter) OrEq(column string, param any) *SqlDeleter

func (*SqlDeleter) OrGe

func (d *SqlDeleter) OrGe(column string, param any) *SqlDeleter

func (*SqlDeleter) OrGt

func (d *SqlDeleter) OrGt(column string, param any) *SqlDeleter

func (*SqlDeleter) OrLe

func (d *SqlDeleter) OrLe(column string, param any) *SqlDeleter

func (*SqlDeleter) OrLt

func (d *SqlDeleter) OrLt(column string, param any) *SqlDeleter

func (*SqlDeleter) OrNotEq

func (d *SqlDeleter) OrNotEq(column string, param any) *SqlDeleter

func (*SqlDeleter) RightLike

func (d *SqlDeleter) RightLike(column string, param string) *SqlDeleter

func (*SqlDeleter) Where

func (d *SqlDeleter) Where(column string, param any) *SqlDeleter

type SqlInserter

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

func NewSqlInserter

func NewSqlInserter() *SqlInserter

func (*SqlInserter) Build

func (o *SqlInserter) Build() (string, []any)

func (*SqlInserter) GetParameters

func (o *SqlInserter) GetParameters() []any

func (*SqlInserter) GetSql

func (o *SqlInserter) GetSql() string

func (*SqlInserter) Insert

func (o *SqlInserter) Insert(entity any) *SqlInserter

type SqlSelector

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

func NewSqlSelector

func NewSqlSelector() *SqlSelector

func (*SqlSelector) And

func (d *SqlSelector) And(cond string, params ...any) *SqlSelector

func (*SqlSelector) Append

func (d *SqlSelector) Append(appendSql string, params ...any) *SqlSelector

func (*SqlSelector) Build

func (d *SqlSelector) Build() (string, []any)

func (*SqlSelector) Eq

func (d *SqlSelector) Eq(column string, param any) *SqlSelector

func (*SqlSelector) From

func (d *SqlSelector) From(table string, alias ...string) *SqlSelector

func (*SqlSelector) Ge

func (d *SqlSelector) Ge(column string, param any) *SqlSelector

func (*SqlSelector) GetParameters

func (d *SqlSelector) GetParameters() []any

func (*SqlSelector) GetSql

func (d *SqlSelector) GetSql() string

func (*SqlSelector) Gt

func (d *SqlSelector) Gt(column string, param any) *SqlSelector

func (*SqlSelector) In

func (d *SqlSelector) In(column string, params ...any) *SqlSelector

func (*SqlSelector) IsNotNull

func (d *SqlSelector) IsNotNull(column string) *SqlSelector

func (*SqlSelector) IsNull

func (d *SqlSelector) IsNull(column string) *SqlSelector

func (*SqlSelector) Join

func (d *SqlSelector) Join(table string, alias ...string) *SqlSelector

func (*SqlSelector) Le

func (d *SqlSelector) Le(column string, param any) *SqlSelector

func (*SqlSelector) LeftLike

func (d *SqlSelector) LeftLike(column string, param string) *SqlSelector

func (*SqlSelector) Like

func (d *SqlSelector) Like(column string, param string) *SqlSelector

func (*SqlSelector) Lt

func (d *SqlSelector) Lt(column string, param any) *SqlSelector

func (*SqlSelector) NotEq

func (d *SqlSelector) NotEq(column string, param any) *SqlSelector

func (*SqlSelector) NotIn

func (d *SqlSelector) NotIn(column string, params ...any) *SqlSelector

func (*SqlSelector) NotLike

func (d *SqlSelector) NotLike(column string, param string) *SqlSelector

func (*SqlSelector) On

func (d *SqlSelector) On(onCond string) *SqlSelector

func (*SqlSelector) Or

func (d *SqlSelector) Or(cond string, params ...any) *SqlSelector

func (*SqlSelector) OrEq

func (d *SqlSelector) OrEq(column string, param any) *SqlSelector

func (*SqlSelector) OrGe

func (d *SqlSelector) OrGe(column string, param any) *SqlSelector

func (*SqlSelector) OrGt

func (d *SqlSelector) OrGt(column string, param any) *SqlSelector

func (*SqlSelector) OrLe

func (d *SqlSelector) OrLe(column string, param any) *SqlSelector

func (*SqlSelector) OrLt

func (d *SqlSelector) OrLt(column string, param any) *SqlSelector

func (*SqlSelector) OrNotEq

func (d *SqlSelector) OrNotEq(column string, param any) *SqlSelector

func (*SqlSelector) OrderBy

func (d *SqlSelector) OrderBy(orders ...string) *SqlSelector

func (*SqlSelector) RightLike

func (d *SqlSelector) RightLike(column string, param string) *SqlSelector

func (*SqlSelector) Select

func (d *SqlSelector) Select(columns ...string) *SqlSelector

func (*SqlSelector) Where

func (d *SqlSelector) Where(cond string, params ...any) *SqlSelector

type SqlUpdater

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

func NewSqlUpdater

func NewSqlUpdater() *SqlUpdater

func (*SqlUpdater) And

func (d *SqlUpdater) And(column string, param any) *SqlUpdater

func (*SqlUpdater) Build

func (d *SqlUpdater) Build() (string, []any)

func (*SqlUpdater) Eq

func (d *SqlUpdater) Eq(column string, param any) *SqlUpdater

func (*SqlUpdater) Ge

func (d *SqlUpdater) Ge(column string, param any) *SqlUpdater

func (*SqlUpdater) GetParameters

func (d *SqlUpdater) GetParameters() []any

func (*SqlUpdater) GetSql

func (d *SqlUpdater) GetSql() string

func (*SqlUpdater) Gt

func (d *SqlUpdater) Gt(column string, param any) *SqlUpdater

func (*SqlUpdater) In

func (d *SqlUpdater) In(column string, params ...any) *SqlUpdater

func (*SqlUpdater) IsNotNull

func (d *SqlUpdater) IsNotNull(column string) *SqlUpdater

func (*SqlUpdater) IsNull

func (d *SqlUpdater) IsNull(column string) *SqlUpdater

func (*SqlUpdater) Le

func (d *SqlUpdater) Le(column string, param any) *SqlUpdater

func (*SqlUpdater) LeftLike

func (d *SqlUpdater) LeftLike(column string, param string) *SqlUpdater

func (*SqlUpdater) Like

func (d *SqlUpdater) Like(column string, param string) *SqlUpdater

func (*SqlUpdater) Lt

func (d *SqlUpdater) Lt(column string, param any) *SqlUpdater

func (*SqlUpdater) NotEq

func (d *SqlUpdater) NotEq(column string, param any) *SqlUpdater

func (*SqlUpdater) NotIn

func (d *SqlUpdater) NotIn(column string, params ...any) *SqlUpdater

func (*SqlUpdater) NotLike

func (d *SqlUpdater) NotLike(column string, param string) *SqlUpdater

func (*SqlUpdater) Or

func (d *SqlUpdater) Or(column string, param any) *SqlUpdater

func (*SqlUpdater) OrEq

func (d *SqlUpdater) OrEq(column string, param any) *SqlUpdater

func (*SqlUpdater) OrGe

func (d *SqlUpdater) OrGe(column string, param any) *SqlUpdater

func (*SqlUpdater) OrGt

func (d *SqlUpdater) OrGt(column string, param any) *SqlUpdater

func (*SqlUpdater) OrLe

func (d *SqlUpdater) OrLe(column string, param any) *SqlUpdater

func (*SqlUpdater) OrLt

func (d *SqlUpdater) OrLt(column string, param any) *SqlUpdater

func (*SqlUpdater) OrNotEq

func (d *SqlUpdater) OrNotEq(column string, param any) *SqlUpdater

func (*SqlUpdater) RightLike

func (d *SqlUpdater) RightLike(column string, param string) *SqlUpdater

func (*SqlUpdater) Set

func (d *SqlUpdater) Set(column string, param any) *SqlUpdater

func (*SqlUpdater) SetMap

func (d *SqlUpdater) SetMap(m map[string]any) *SqlUpdater

func (*SqlUpdater) Update

func (d *SqlUpdater) Update(tableName string) *SqlUpdater

func (*SqlUpdater) Where

func (d *SqlUpdater) Where(column string, param any) *SqlUpdater

type TokenizerJiebago

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

func NewTokenizerJiebago

func NewTokenizerJiebago(dicFile string) *TokenizerJiebago

创建中文分词器(jiebago) 参数dicFile为字典文件,传入空时默认为"data/dictionary.txt"

func (*TokenizerJiebago) CutForSearch

func (t *TokenizerJiebago) CutForSearch(str string) []string

按搜索引擎模式进行分词(自动去重、去标点符号、忽略大小写)

func (*TokenizerJiebago) CutForSearchEx

func (t *TokenizerJiebago) CutForSearchEx(str string, addWords []string, delWords []string) []string

按搜索引擎模式进行分词(自动去重、去标点符号、忽略大小写),可自定义添加或删除分词

func (*TokenizerJiebago) IngoreWords

func (t *TokenizerJiebago) IngoreWords(str ...string)

设定忽略词(比如分词结果不想包含无效词“的”或一些敏感词时,可以这里设定)

type TokenizerSego

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

func NewTokenizerSego

func NewTokenizerSego(dicFile string) *TokenizerSego

创建中文分词器(sego) 参数dicFile为字典文件,传入空时默认为"data/dictionary.txt"

func (*TokenizerSego) CutForSearch

func (t *TokenizerSego) CutForSearch(str string) []string

按搜索引擎模式进行分词(自动去重、去标点符号、忽略大小写)

func (*TokenizerSego) CutForSearchEx

func (t *TokenizerSego) CutForSearchEx(str string, addWords []string, delWords []string) []string

按搜索引擎模式进行分词(自动去重、去标点符号、忽略大小写),可自定义添加或删除分词

func (*TokenizerSego) IngoreWords

func (t *TokenizerSego) IngoreWords(str ...string)

设定忽略词(比如分词结果不想包含无效词“的”或一些敏感词时,可以这里设定)

Jump to

Keyboard shortcuts

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