utils

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 50 Imported by: 0

README

常用实用方法

类型转换 AnyToString any -> string

func AnyToString(i interface{}) string


类型转换 JsonToMap json -> map

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


类型转换 MapToJson map -> json

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


类型转换 AnyToMap interface{} -> map[string]interface{}

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


类型转换 AnyToInt interface{} -> int

func AnyToInt(data interface{}) int


类型转换 AnyToInt64 interface{} -> int64

func AnyToInt64(data interface{}) int64


类型转换 AnyToArr interface{} -> []interface{}

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


类型转换 AnyToFloat64 interface{} -> float64

func AnyToFloat64(data interface{}) float64


类型转换 AnyToStrings interface{} -> []string

func AnyToStrings(data interface{}) []string


类型转换 AnyToJson interface{} -> json string

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


类型转换 IntToHex int -> hex

func IntToHex(i int) string


类型转换 Int64ToHex int64 -> hex

func Int64ToHex(i int64) string


类型转换 HexToInt hex -> int

func HexToInt(s string) int


类型转换 HexToInt64 hex -> int

func HexToInt64(s string) int64


类型转换 StrNumToInt64 string -> int64

func StrNumToInt64(str string) int64


类型转换 StrNumToInt string -> int

func StrNumToInt(str string) int


类型转换 StrNumToInt32 string -> int32

func StrNumToInt32(str string) int32


类型转换 StrNumToFloat64 string -> float64

func StrNumToFloat64(str string) float64


类型转换 StrNumToFloat32 string -> float32

func StrNumToFloat32(str string) float32


类型转换 Uint8ToStr []uint8 -> string

func Uint8ToStr(bs []uint8) string


类型转换 StrToByte string -> []byte

func StrToByte(s string) []byte


类型转换 ByteToStr []byte -> string

func ByteToStr(b []byte) string


类型转换 BoolToByte bool -> []byte

func BoolToByte(b bool) []byte


类型转换 ByteToBool []byte -> bool

func ByteToBool(b []byte) bool


类型转换 IntToByte int -> []byte

func IntToByte(i int) []byte


类型转换 ByteToInt []byte -> int

func ByteToInt(b []byte) int


类型转换 func Int64ToByte(i int64) []byte

func Int64ToByte(i int64) []byte


类型转换 ByteToInt64 []byte -> int64

func ByteToInt64(b []byte) int64


类型转换 Float32ToByte float32 -> []byte

func Float32ToByte(f float32) []byte


类型转换 Float32ToUint32 float32 -> uint32

func Float32ToUint32(f float32) uint32


类型转换 ByteToFloat32 []byte -> float32

func ByteToFloat32(b []byte) float32


类型转换 Float64ToByte float64 -> []byte

func Float64ToByte(f float64) []byte


类型转换 Float64ToUint64 float64 -> uint64

func Float64ToUint64(f float64) uint64


类型转换 ByteToFloat64 []byte -> float64

func ByteToFloat64(b []byte) float64


类型转换 StructToMap struct -> map[string]interface{}

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


EncodeByte encode byte

func EncodeByte(v interface{}) []byte


DecodeByte decode byte

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


类型转换 ByteToBit []byte -> []uint8 (bit)

func ByteToBit(b []byte) []uint8


类型转换 BitToByte []uint8 -> []byte

func BitToByte(b []uint8) []byte


类型转换 StructToMapV2 Struct -> map

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

参数

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

类型转换 StructToMapV3 struct -> map

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


类型转换 PanicToError panic -> error

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


类型转换 P2E panic -> error

func P2E()


类型转换 ByteToBinaryString 字节 -> 二进制字符串

func ByteToBinaryString(data byte) (str string)


类型转换 MapStrToAny map[string]string -> map[string]interface{}

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


类型转换 ByteToGBK byte -> gbk byte

func ByteToGBK(strBuf []byte) []byte


类型转换 Int64ToStr int64 -> string

func Int64ToStr(i int64) string


































Documentation

Index

Constants

View Source
const (
	UTF8    = Charset("UTF-8")
	GB18030 = Charset("GB18030")
	GBK     = Charset("GBK")
	GB2312  = Charset("GB2312")
)
View Source
const (
	CBC = "CBC"
	ECB = "ECB"
	CFB = "CFB"
	CTR = "CTR"
)
View Source
const (
	TimeTemplate = "2006-01-02 15:04:05"

	TimeMilliTemplate = "2006-01-02 15:04:05.000"

	// 定义每分钟的秒数
	SecondsPerMinute = 60

	// 定义每小时的秒数
	SecondsPerHour = SecondsPerMinute * 60

	// 定义每天的秒数
	SecondsPerDay = SecondsPerHour * 24
)
View Source
const DefaultABC = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Variables

View Source
var Leaps = []int{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

Leaps 闰年的天数

View Source
var Pyears = []int{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

Pyears 平年天数

Functions

func AbPathByCaller

func AbPathByCaller() string

AbPathByCaller 获取当前执行文件绝对路径(go run)

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 BIG5To

func BIG5To(dstCharset string, src string) (dst string, err error)

BIG5To big to

func Base64Decode

func Base64Decode(str string) (string, error)

Base64Decode base64 解码

func Base64Encode

func Base64Encode(str string) string

Base64Encode base64 编码

func Base64UrlDecode

func Base64UrlDecode(str string) (string, error)

Base64UrlDecode base64 url 解码

func Base64UrlEncode

func Base64UrlEncode(str string) string

Base64UrlEncode base64 url 编码

func BeginDayUnix

func BeginDayUnix() int64

BeginDayUnix 获取当天 0点

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 CleaningStr

func CleaningStr(str string) string

CleaningStr 清理字符串前后空白 和回车 换行符号

func CompressDirZip

func CompressDirZip(src, outFile string) error

CompressDirZip 压缩目录

func CompressFiles

func CompressFiles(files []string, dest string) error

CompressFiles 压缩很多文件 files 文件数组,可以是不同dir下的文件或者文件夹 dest 压缩文件存放地址

func ConvertByte2String

func ConvertByte2String(byte []byte, charset Charset) string

ConvertByte2String 编码转换

func ConvertGBKToStr

func ConvertGBKToStr(gbkStr string) string

ConvertGBKToStr 将GBK编码的字符串转换为utf-8编码

func ConvertStrToGBK

func ConvertStrToGBK(str string) string

ConvertStrToGBK 将utf-8编码的字符串转换为GBK编码

func Date2Timestamp

func Date2Timestamp(date string) int64

func DayAgo

func DayAgo(i int) int64

DayAgo 获取多少天前的时间戳

func DayAgoDate

func DayAgoDate(i int) string

DayAgoDate 获取多少天前的时间戳

func DayAgoDateYMD

func DayAgoDateYMD(i int) string

func DayDiff

func DayDiff(beginDay string, endDay string) int

DayDiff 两个时间字符串的日期差

func DeCompressTAR

func DeCompressTAR(tarFile, dest string) error

DeCompressTAR tar 解压文件

func DeCompressZIP

func DeCompressZIP(zipFile, dest string) error

DeCompressZIP zip解压文件

func Deadline

func Deadline(timestamp int64) string

当前时间戳在今天是否结束

func DecodeByte

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

DecodeByte decode byte

func DecompressionZipFile

func DecompressionZipFile(src, dest string) error

DecompressionZipFile zip压缩文件

func DeepCopy

func DeepCopy(dst, src interface{}) error

DeepCopy 深copy

func DeepEqual

func DeepEqual(a, b interface{}) bool

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

func EncodeByte

func EncodeByte(v interface{}) []byte

EncodeByte encode byte

func EndDayUnix

func EndDayUnix() int64

EndDayUnix 获取当天 24点

func Exists

func Exists(path string) bool

Exists 路径是否存在

func FileExists

func FileExists(name string) bool

FileExists 文件是否存在

func FileMd5

func FileMd5(path string) (string, error)

FileMd5 file md5 文件md5

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 GB18030To

func GB18030To(dstCharset string, src string) (dst string, err error)

GB18030To gb18030 to

func GB2312To

func GB2312To(dstCharset string, src string) (dst string, err error)

GB2312To gb2312 to

func GDKTo

func GDKTo(dstCharset string, src string) (dst string, err error)

GDKTo gdk to

func Get16MD5Encode

func Get16MD5Encode(data string) string

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

func GetAllFile

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

GetAllFile 获取目录下的所有文件

func GetChineseMonthDay

func GetChineseMonthDay(date string) (rmonth, rday int64)

GetChineseMonthDay 获取农历

func GetMD5Encode

func GetMD5Encode(data string) string

GetMD5Encode 获取Md5编码

func GetNowPath

func GetNowPath() string

GetNowPath 获取当前运行路径

func GetPointClassHTML

func GetPointClassHTML(htmlStr, label, val string) ([]string, error)

GetPointClassHTML 获取指定标签class属性的html

func GetPointHTML

func GetPointHTML(htmlStr, label, attr, val string) ([]string, error)

GetPointHTML 获取指定位置的HTML, 用标签, 标签属性, 属性值来定位

func GetPointIDHTML

func GetPointIDHTML(htmlStr, label, val string) ([]string, error)

GetPointIDHTML 获取指定标签id属性的html

func GetWD

func GetWD() string

GetWD 获取当前工作目录

func GzipCompress

func GzipCompress(src []byte) []byte

GzipCompress gzip压缩

func GzipDecompress

func GzipDecompress(src []byte) []byte

GzipDecompress gzip解压

func HZGB2312To

func HZGB2312To(dstCharset string, src string) (dst string, err error)

HZGB2312To hzgb2312 to

func HexToInt

func HexToInt(s string) int

HexToInt hex -> int

func HexToInt64

func HexToInt64(s string) int64

HexToInt64 hex -> int

func HmacMD5

func HmacMD5(str, key string) string

HmacMD5 hmac md5

func HmacSHA1

func HmacSHA1(str, key string) string

HmacSHA1 hmac sha1

func HmacSHA256

func HmacSHA256(str, key string) string

HmacSHA256 hmac sha256

func HmacSHA512

func HmacSHA512(str, key string) string

HmacSHA512 hmac sha512

func HourAgo

func HourAgo(i int) int64

HourAgo 获取多少小时前的时间戳

func ID

func ID() int64

func ID64

func ID64() (int64, error)

func IDMd5

func IDMd5() string

func IDShort

func IDShort() int64

func IDStr

func IDStr() string

func IF

func IF(condition bool, a, b interface{}) interface{}

IF 三元表达式 use: IF(a>b, a, b).(int)

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 IsContainStr

func IsContainStr(items []string, item string) bool

IsContainStr 字符串是否等于items中的某个元素

func IsDir

func IsDir(path string) bool

IsDir 是否是目录

func IsElementStr

func IsElementStr(listData []string, element string) bool

IsElementStr 判断字符串是否与数组里的某个字符串相同

func IsFile

func IsFile(path string) bool

IsFile 是否是文件

func IsHaveKey

func IsHaveKey(data map[string]interface{}, key string) bool

IsHaveKey map[string]interface{} 是否存在 输入的key

func IsJson

func IsJson(str string) bool

IsJson 是否是json格式

func IsLeap

func IsLeap(year int) bool

IsLeap 是否是闰年

func IsPic

func IsPic(suffix string) bool

IsPic 判断是否是图片

func IsToday

func IsToday(timestamp int64) string

IsToday 判断是否是今天 "2006-01-02 15:04:05" timestamp 需要判断的时间

func IsTodayList

func IsTodayList(timestamp int64) string

IsTodayList 列表页的时间显示 "01-02 15:04"

func IsUtf8

func IsUtf8(buf []byte) bool

IsUtf8 是否是utf8编码

func JsonFind

func JsonFind(jsonStr, find string) (interface{}, error)

JsonFind 按路径寻找指定json值 用法参考 ./_examples/json/main.go @find : 寻找路径,与目录的url类似, 下面是一个例子: json: {a:[{b:1},{b:2}]} find=/a/[0] => {b:1} find=a/[0]/b => 1

func JsonFind2Arr

func JsonFind2Arr(jsonStr, find string) ([]interface{}, error)

JsonFind2Arr 寻找json,输出 []interface{}

func JsonFind2Json

func JsonFind2Json(jsonStr, find string) (string, error)

JsonFind2Json 寻找json,输出 json格式字符串

func JsonFind2Map

func JsonFind2Map(jsonStr, find string) (map[string]interface{}, error)

JsonFind2Map 寻找json,输出 map[string]interface{}

func JsonToMap

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

JsonToMap json -> map

func LatestDate

func LatestDate(date int) []string

LatestDate 最近好多天

func Map2Slice

func Map2Slice(data any) []any

Map2Slice Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"]

func MapCopy

func MapCopy[K, V comparable](data map[K]V) (copy map[K]V)

func MapMergeCopy

func MapMergeCopy[K, V comparable](src ...map[K]V) (copy map[K]V)

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 Md5Uppercase

func Md5Uppercase(str string) string

func MinuteAgo

func MinuteAgo(i int) int64

MinuteAgo 获取多少分钟前的时间戳

func NewShortCode added in v0.1.4

func NewShortCode() string

NewShortCode 获取一个不重复的短code;常用与短链code生成;

func NowDate

func NowDate() string

func NowDateHMS

func NowDateHMS() string

func NowDateLayout

func NowDateLayout(layout string) string

func NowDateYMD

func NowDateYMD() string

func NowToEnd

func NowToEnd() (int64, error)

NowToEnd 计算当前时间到这天结束还有多久

func OrderMap added in v0.1.4

func OrderMap[K, V comparable]() *orderMap[K, V]

OrderMap ues: OrderMap[K, V]()

func OutJsonFile

func OutJsonFile(data interface{}, fileName string) error

OutJsonFile 将data输出到json文件

func P2E

func P2E()

P2E panic -> error

func PBKDF2

func PBKDF2(str, salt []byte, iterations, keySize int) []byte

func PanicToError

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

PanicToError panic -> error

func PathExists

func PathExists(path string)

PathExists 目录不存在则创建

func RandomIntCaptcha

func RandomIntCaptcha(captchaLen int) string

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

func RandomString

func RandomString(list []string) string

func RegFindAll

func RegFindAll(regStr, rest string) [][]string

func RegFindAllTxt

func RegFindAllTxt(regStr, rest string) (dataList []string)

func ReplaceAllToOne

func ReplaceAllToOne(str string, from []string, to string) string

ReplaceAllToOne 批量统一替换字符串

func ResolveTime

func ResolveTime(seconds int) (day int, hour int, minute int, sy int)

ResolveTime 将传入的“秒”解析为3种时间单位

func ResolveTimeStr

func ResolveTimeStr(seconds int) string

func SearchBytesIndex

func SearchBytesIndex(bSrc []byte, b byte) int

SearchBytesIndex []byte 字节切片 循环查找

func SizeFormat

func SizeFormat(size int64) string

SizeFormat 字节的单位转换 保留两位小数

func Slice2Map

func Slice2Map(slice any) map[any]any

Slice2Map ["K1", "v1", "K2", "v2"] => {"K1": "v1", "K2": "v2"} ["K1", "v1", "K2"] => nil

func SliceContains added in v0.1.4

func SliceContains[V comparable](a []V, v V) bool

func SliceCopy

func SliceCopy[V comparable](a []V) []V

func SliceDeduplicate added in v0.1.4

func SliceDeduplicate[V comparable](a []V) []V

func SliceDel added in v0.1.4

func SliceDel[V comparable](a []V, i int) []V

func SliceMax added in v0.1.4

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

func SliceMin added in v0.1.4

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

func SlicePop added in v0.1.4

func SlicePop[V comparable](a []V) (V, []V)

func SliceReverse added in v0.1.4

func SliceReverse[V comparable](a []V) []V

func SliceShuffle added in v0.1.4

func SliceShuffle[V comparable](a []V) []V

func StrDeleteSpace

func StrDeleteSpace(str string) string

StrDeleteSpace 删除字符串前后的空格

func StrDuplicates

func StrDuplicates(a []string) []string

StrDuplicates 数组,切片去重和去空串

func StrLen

func StrLen(str string) int

StrLen 获取字符长度

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 TickerRun

func TickerRun(t time.Duration, runFirst bool, f func())

TickerRun 间隔运行 t: 间隔时间, runFirst: 间隔前或者后执行 f: 运行的方法

func Timestamp

func Timestamp() string

Timestamp 获取时间戳

func Timestamp2Date

func Timestamp2Date(timestamp int64) string

func Timestamp2Week

func Timestamp2Week(timestamp int64) string

func Timestamp2WeekXinQi

func Timestamp2WeekXinQi(timestamp int64) string

func ToBIG5

func ToBIG5(srcCharset string, src string) (dst string, err error)

ToBIG5 to big5

func ToGB18030

func ToGB18030(srcCharset string, src string) (dst string, err error)

ToGB18030 to gb18030

func ToGB2312

func ToGB2312(srcCharset string, src string) (dst string, err error)

ToGB2312 to gb2312

func ToGDK

func ToGDK(srcCharset string, src string) (dst string, err error)

ToGDK to gdk

func ToHZGB2312

func ToHZGB2312(srcCharset string, src string) (dst string, err error)

ToHZGB2312 to hzgb2312

func ToUTF16

func ToUTF16(srcCharset string, src string) (dst string, err error)

ToUTF16 to utf16

func ToUTF8

func ToUTF8(srcCharset string, src string) (dst string, err error)

ToUTF8 to utf8

func URIStr

func URIStr(url string) string

func UTF16To

func UTF16To(dstCharset string, src string) (dst string, err error)

UTF16To utf16 to

func UTF8To

func UTF8To(dstCharset string, src string) (dst string, err error)

UTF8To utf8 to

func Uint8ToStr

func Uint8ToStr(bs []uint8) string

Uint8ToStr []uint8 -> string

func UnescapeUnicode

func UnescapeUnicode(raw []byte) ([]byte, error)

UnescapeUnicode Unicode 转码

func UnicodeDec

func UnicodeDec(raw string) string

func UnicodeDecByte

func UnicodeDecByte(raw []byte) []byte

Types

type AES

type AES interface {
	Encrypt(str, key []byte) ([]byte, error)
	Decrypt(str, key []byte) ([]byte, error)
}

AES AES interface

func NewAES

func NewAES(typeName string, arg ...[]byte) AES

NewAES : use NewAES(AES_CBC)

type Bar

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

Bar 终端显示的进度条

func (*Bar) Finish

func (bar *Bar) Finish()

func (*Bar) NewOption

func (bar *Bar) NewOption(start, total int64)

func (*Bar) NewOptionWithGraph

func (bar *Bar) NewOptionWithGraph(start, total int64, graph string)

func (*Bar) Play

func (bar *Bar) Play(cur int64)

type Charset

type Charset string

Charset 字符集类型

type Cron

type Cron struct {
	C *cron.Cron
}

func NewCron

func NewCron() *Cron

func (*Cron) AddAtDayWhatTime

func (c *Cron) AddAtDayWhatTime(f func(), i int)

AddAtDayWhatTime 每天的几点 i=0为每天

func (*Cron) AddAtFriday

func (c *Cron) AddAtFriday(f func())

AddAtFriday 每周五

func (*Cron) AddAtHours

func (c *Cron) AddAtHours(f func(), i int)

AddAtHours 每多少小时 i=0为每小时

func (*Cron) AddAtMinute

func (c *Cron) AddAtMinute(f func(), i int)

AddAtMinute 每多少分钟 i=0为每分钟

func (*Cron) AddAtMonday

func (c *Cron) AddAtMonday(f func())

AddAtMonday 每周一

func (*Cron) AddAtSaturday

func (c *Cron) AddAtSaturday(f func())

AddAtSaturday 每周六

func (*Cron) AddAtSunday

func (c *Cron) AddAtSunday(f func())

AddAtSunday 每周日

func (*Cron) AddAtThursday

func (c *Cron) AddAtThursday(f func())

AddAtThursday 每周四

func (*Cron) AddAtTuesday

func (c *Cron) AddAtTuesday(f func())

AddAtTuesday 每周二

func (*Cron) AddAtWednesday

func (c *Cron) AddAtWednesday(f func())

AddAtWednesday 每周三

func (*Cron) Run

func (c *Cron) Run()

type DES

type DES interface {
	Encrypt(str, key []byte) ([]byte, error)
	Decrypt(str, key []byte) ([]byte, error)
}

DES DES interface

func NewDES

func NewDES(typeName string, arg ...[]byte) DES

NewDES : use NewDES(DES_CBC)

type GDMap

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

GDMap 固定顺序map

func NewGDMap

func NewGDMap() *GDMap

NewGDMap ues: NewGDMap().Add(k,v)

func (*GDMap) Add

func (m *GDMap) Add(key string, value interface{}) *GDMap

Add 添加kv

func (*GDMap) AddMap

func (m *GDMap) AddMap(data map[string]interface{}) *GDMap

AddMap 写入map

func (*GDMap) CheckValue

func (m *GDMap) CheckValue(value interface{}) bool

CheckValue 查看map是否存在指定的值

func (*GDMap) Del

func (m *GDMap) Del(key string) *GDMap

Del 删除指定key的值

func (*GDMap) Get

func (m *GDMap) Get(key string) interface{}

Get 通过key获取值

func (*GDMap) KeyList

func (m *GDMap) KeyList() []string

KeyList 打印map所有的key

func (*GDMap) Len

func (m *GDMap) Len() int

Len map的长度

func (*GDMap) Range

func (m *GDMap) Range(f func(k string, v interface{})) *GDMap

Range 遍历map

func (*GDMap) RangeAt

func (m *GDMap) RangeAt(f func(id int, k string, v interface{})) *GDMap

RangeAt Range 遍历map含顺序id

func (*GDMap) Reverse

func (m *GDMap) Reverse()

Reverse map反序

type GDMaper

type GDMaper interface {
	Add(key string, value interface{}) *GDMap
	Get(key string) interface{}
	Del(key string) *GDMap
	Len() int
	KeyList() []string
	AddMap(data map[string]interface{}) *GDMap
	Range(f func(k string, v interface{})) *GDMap
	RangeAt(f func(id int, k string, v interface{})) *GDMap
	CheckValue(value interface{}) bool // 检查是否存在某个值
	Reverse()                          //反序
}

GDMaper 固定顺序 Map 接口

type IdWorker

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

func (*IdWorker) InitIdWorker

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

func (*IdWorker) NextId

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

NextId 返回一个唯一的 INT64 ID

type JWT

type JWT struct {
	Claims jwt.MapClaims
	Secret string
	Expire int
}

func NewJWT

func NewJWT(secret string, expire int) *JWT

func (*JWT) AddClaims

func (j *JWT) AddClaims(k string, v interface{}) *JWT

func (*JWT) Get

func (j *JWT) Get(k string) interface{}

func (*JWT) GetBool

func (j *JWT) GetBool(k string) bool

func (*JWT) GetFloat64

func (j *JWT) GetFloat64(k string) float64

func (*JWT) GetInt

func (j *JWT) GetInt(k string) int

func (*JWT) GetInt64

func (j *JWT) GetInt64(k string) int64

func (*JWT) GetString

func (j *JWT) GetString(k string) string

func (*JWT) IsExpire

func (j *JWT) IsExpire() bool

func (*JWT) ParseToken

func (j *JWT) ParseToken(token string) error

func (*JWT) Print

func (j *JWT) Print()

func (*JWT) Token

func (j *JWT) Token() (string, error)

type Paginator

type Paginator struct {
	Request     *http.Request //请求
	PerPageNums int           // 一页显示多少条记录
	MaxPages    int           //一共有多少页
	// contains filtered or unexported fields
}

Paginator 分页器

func NewPaginator

func NewPaginator(req *http.Request, per int, nums interface{}) *Paginator

NewPaginator 创建分页

func (*Paginator) HasNext

func (p *Paginator) HasNext() bool

HasNext 是否存在下一页

func (*Paginator) HasPages

func (p *Paginator) HasPages() bool

HasPages 是否存在页

func (*Paginator) HasPrev

func (p *Paginator) HasPrev() bool

HasPrev 是否存在上一页

func (*Paginator) IsActive

func (p *Paginator) IsActive(page int) bool

IsActive 是否点击

func (*Paginator) Nums

func (p *Paginator) Nums() int64

Nums 得到总记录数

func (*Paginator) Offset

func (p *Paginator) Offset() int

Offset 偏移量

func (*Paginator) Page

func (p *Paginator) Page() int

Page 得到当前传入的页数

func (p *Paginator) PageLink(page int) string

PageLink 得到页面的链接

func (*Paginator) PageLinkFirst

func (p *Paginator) PageLinkFirst() string

PageLinkFirst 第一页的链接

func (*Paginator) PageLinkLast

func (p *Paginator) PageLinkLast() string

PageLinkLast 最后一页的链接

func (*Paginator) PageLinkNext

func (p *Paginator) PageLinkNext() string

PageLinkNext 下一页的链接

func (*Paginator) PageLinkPrev

func (p *Paginator) PageLinkPrev() string

PageLinkPrev 上一页链接

func (*Paginator) PageNums

func (p *Paginator) PageNums() int

PageNums 计算总页数

func (*Paginator) Pages

func (p *Paginator) Pages() []int

Pages 分页

func (*Paginator) SetNums

func (p *Paginator) SetNums(nums interface{})

SetNums 赋值总记录数

type Set

type Set map[any]struct{}

func NewSet added in v0.1.4

func NewSet() Set

func (Set) Add

func (s Set) Add(key any)

func (Set) DebugPrint added in v0.1.4

func (s Set) DebugPrint()

func (Set) Delete

func (s Set) Delete(key any)

func (Set) Has

func (s Set) Has(key any) bool

type Stack

type Stack[K comparable] struct {
	// contains filtered or unexported fields
}

func NewStack added in v0.1.4

func NewStack[K comparable]() *Stack[K]

func (*Stack[K]) DebugPrint added in v0.1.4

func (s *Stack[K]) DebugPrint()

func (*Stack[K]) Pop

func (s *Stack[K]) Pop() K

func (*Stack[K]) Push

func (s *Stack[K]) Push(data K)

Jump to

Keyboard shortcuts

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