util

package
v1.2.49 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: Apache-2.0 Imports: 38 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// DefaultVirtualNodeSize 默认虚拟节点
	DefaultVirtualNodeSize = 400
)

Variables

View Source
var (
	HttpClient      = NewHttpClient()
	ContentTypeJson = "application/json"
)
View Source
var (
	RandChats = []string{
		"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
		"a", "b", "c", "d", "e", "f", "g",
		"h", "i", "j", "k", "l", "m", "n",
		"o", "p", "q", "r", "s", "t", "u",
		"v", "w", "z", "y", "z",
		"A", "B", "C", "D", "E", "F", "G",
		"H", "I", "J", "K", "L", "M", "N",
		"O", "P", "Q", "R", "S", "T", "U",
		"V", "W", "Z", "Y", "Z",
		"_",
	}
	RandChatsSize = len(RandChats)
)
View Source
var (
	FirstName = []string{}/* 292 elements not displayed */

	LastName = []string{}/* 350 elements not displayed */

	FirstNameLen = len(FirstName)
	LastNameLen  = len(LastName)
)
View Source
var (
	// DefaultTimeFormatLayout 默认时间格式化
	DefaultTimeFormatLayout = "2006-01-02 15:04:05"
)
View Source
var JsonConfigDefault = jsoniter.Config{
	EscapeHTML: false,
}.Froze()

JsonConfigDefault the default API

View Source
var JsonConfigUseNumber = jsoniter.Config{
	EscapeHTML: false,
	UseNumber:  true,
}.Froze()
View Source
var (
	Logger = NewDefaultLogger()
)

Functions

func AesCBCDecrypt added in v0.0.2

func AesCBCDecrypt(encrypt, key []byte) ([]byte, error)

func AesCBCEncrypt added in v0.0.2

func AesCBCEncrypt(origData, key []byte) ([]byte, error)

func AesDecryptCBCByKey added in v0.0.2

func AesDecryptCBCByKey(encrypt string, key string) (res string, err error)

AesDecryptCBCByKey AES解密,CBC模式 AesDecryptCBCByKey("这是加密后的文本", "这是密钥")

func AesDecryptECBByKey added in v0.0.2

func AesDecryptECBByKey(encrypt string, key string) (res string, err error)

AesDecryptECBByKey AES解密,ECB模式 AesDecryptECBByKey("这是加密后的文本", "这是密钥")

func AesECBDecrypt added in v0.0.2

func AesECBDecrypt(data, key []byte) ([]byte, error)

func AesECBEncrypt added in v0.0.2

func AesECBEncrypt(data, key []byte) ([]byte, error)

func AesEncryptCBCByKey added in v0.0.2

func AesEncryptCBCByKey(origData string, key string) (res string, err error)

AesEncryptCBCByKey AES加密,CBC模式,返回 base64 字符 AesEncryptCBCByKey("这是需要加密的文本", "这是密钥")

func AesEncryptECBByKey added in v0.0.2

func AesEncryptECBByKey(origData string, key string) (res string, err error)

AesEncryptECBByKey AES加密,ECB模式,返回 base64 字符 AesEncryptECBByKey("这是需要加密的文本", "这是密钥")

func AnyJoin added in v1.2.32

func AnyJoin(sep string, es ...any) (res string)

AnyJoin 任意切片拼接

func ArrayIndexOf added in v0.0.2

func ArrayIndexOf(array interface{}, v interface{}) (index int)

ArrayIndexOf 返回 某个值 在数组中的索引位置,未找到返回 -1 ArrayIndexOf(["a", "b", "c"], "d")

func BindJsonBody added in v1.2.23

func BindJsonBody(body io.ReadCloser, obj interface{}) (str string, err error)

func BindXmlBody added in v1.2.23

func BindXmlBody(body io.ReadCloser, obj interface{}) (bodyXml string, err error)

func FirstToLower added in v0.0.2

func FirstToLower(str string) (res string)

FirstToLower 字符首字母小写 @param str string "任意字符串" @return string FirstToLower("Abc")

func FirstToUpper added in v0.0.2

func FirstToUpper(str string) (res string)

FirstToUpper 字符首字母大写 @param str string "任意字符串" @return string FirstToUpper("abc")

func FormatPath added in v0.0.2

func FormatPath(path string) string

FormatPath 格式化路径 FormatPath("/x/x/xxx\xx\xx")

func FormatZapArgs added in v0.5.8

func FormatZapArgs(args ...interface{}) (msg []interface{}, fields []zap.Field)

func GenStringJoin added in v1.2.34

func GenStringJoin(len int, str string, sep string) (res string)

GenStringJoin 生成 字符串 拼接 GenStringJoin(5, "xx", ",") 表示 生成 xx,xx,xx,xx,xx

func GetAbsolutePath added in v0.0.2

func GetAbsolutePath(path string) (absolutePath string)

GetAbsolutePath 获取路径觉得路径 GetAbsolutePath("/x/x/xxx\xx\xx")

func GetDefaultOptions added in v0.7.1

func GetDefaultOptions(skip int) (options []zap.Option)

func GetFileType added in v0.0.2

func GetFileType(fSrc []byte) string

GetFileType 用文件前面几个字节来判断 fSrc: 文件字节流(就用前面几个字节)

func GetFormatByTime added in v0.0.2

func GetFormatByTime(v time.Time) string

GetFormatByTime 获取格式化时间 "2006-01-02 15:04:05" @param v time.Time "时间" GetFormatByTime(time)

func GetIpFromAddr added in v0.0.2

func GetIpFromAddr(addr net.Addr) net.IP

GetIpFromAddr 获取当前IP

func GetJson added in v1.2.23

func GetJson[T any](url string, response T) (res T, body string, err error)

func GetJsonHeader added in v1.2.23

func GetJsonHeader[T any](url string, header http.Header, response T) (res T, body string, err error)

func GetLocalIPList added in v0.0.2

func GetLocalIPList() (ipList []net.IP)

GetLocalIPList 获取当前IP列表

func GetLock added in v0.0.2

func GetLock(key string) (lock sync.Locker)

GetLock 获取一个Locker,如果不存在,则新建 obj = GetLock("user:1") obj.Lock() obj.Unlock()

func GetLogger added in v0.5.7

func GetLogger() *zap.Logger

GetLogger 获取logger输出对象

func GetMD5 added in v0.0.3

func GetMD5(str string) string

GetMD5 获取MD5字符串 @param str string "需要MD5的字符串" GetMD5("这是需要MD5的文本")

func GetMilliByTime added in v0.5.7

func GetMilliByTime(v time.Time) int64

GetMilliByTime 获取时间戳 到毫秒 @param v time.Time "时间" GetMilliByTime(time)

func GetNanoByTime added in v0.5.7

func GetNanoByTime(v time.Time) int64

GetNanoByTime 获取时间戳 到纳秒 @param v time.Time "时间" GetNanoByTime(time)

func GetNow added in v0.0.2

func GetNow() time.Time

GetNow 获取当前时间 GetNow()

func GetNowFormat added in v0.0.2

func GetNowFormat() string

GetNowFormat 获取当前格式化时间 "2006-01-02 15:04:05" GetNowFormat()

func GetNowMilli added in v0.5.7

func GetNowMilli() int64

GetNowMilli 获取当前时间戳 到毫秒 GetNowMilli()

func GetNowNano added in v0.5.7

func GetNowNano() int64

GetNowNano 获取当前时间戳 到纳秒 GetNowNano()

func GetNowSecond added in v0.0.2

func GetNowSecond() int64

GetNowSecond 获取当前时间戳 到秒 GetNowSecond()

func GetRootDir added in v0.0.2

func GetRootDir() string

GetRootDir 获取当前程序根路径

func GetSecondByTime added in v0.0.2

func GetSecondByTime(v time.Time) int64

GetSecondByTime 获取时间戳 到秒 @param v time.Time "时间" GetSecondByTime(time)

func GetStringValue added in v0.0.2

func GetStringValue(value interface{}) (valueString string)

GetStringValue 将传入的值转为字符串 @param value interface{} "任意值" @return string GetStringValue(arg)

func GetTempDir added in v0.0.7

func GetTempDir() (dir string, err error)

GetTempDir 获取临时目录

func GetUUID added in v0.0.3

func GetUUID() (res string)

GetUUID 生成UUID GetUUID()

func GetValueByType added in v0.8.8

func GetValueByType(valueType reflect.Type, data interface{}) (res interface{}, err error)

func GzipBytes added in v0.0.3

func GzipBytes(data []byte) ([]byte, error)

GzipBytes 压缩

func HasPrefix added in v1.2.30

func HasPrefix(arg string, trim string) bool

HasPrefix 匹配的 前缀

func HasSuffix added in v1.2.30

func HasSuffix(arg string, trim string) bool

HasSuffix 匹配的 后缀

func Hump added in v1.2.30

func Hump(name string) string

Hump 转换为驼峰命名法则 “_”后的字母大写 Hump("abc_def")

func Int64IndexOf added in v0.0.2

func Int64IndexOf(array []int64, v int64) (index int)

Int64IndexOf 返回 某个值 在数组中的索引位置,未找到返回 -1 Int64IndexOf([1,2,3], 2)

func Int64Join added in v1.2.33

func Int64Join(es []int64, sep string) (res string)

Int64Join int64 拼接

func IntIndexOf added in v0.0.2

func IntIndexOf(array []int, v int) (index int)

IntIndexOf 返回 某个值 在数组中的索引位置,未找到返回 -1 IntIndexOf([1,2,3], 2)

func IntJoin added in v1.2.33

func IntJoin(es []int, sep string) (res string)

IntJoin int 拼接

func IsEmpty added in v0.0.2

func IsEmpty(v interface{}) bool

IsEmpty 是否为nil或空字符串 @param v interface{} "传入任意值" @return bool IsEmpty(arg)

func IsFalse added in v0.0.2

func IsFalse(v interface{}) (res bool)

IsFalse 是否为否 判断不是true、"true"、1、"1" @param v interface{} "传入任意值" @return bool IsFalse(arg)

func IsNotEmpty added in v0.0.2

func IsNotEmpty(v interface{}) bool

IsNotEmpty 是否不为nil或空字符串 @param v interface{} "传入任意值" @return bool IsNotEmpty(arg)

func IsNotNull added in v0.4.6

func IsNotNull(v interface{}) bool

IsNotNull 是否不为nil或空字符串 @param v interface{} "传入任意值" @return bool IsNotNull(arg)

func IsNull added in v0.4.6

func IsNull(v interface{}) bool

IsNull 是否为nil @param v interface{} "传入任意值" @return bool IsNull(arg)

func IsSubPath added in v1.1.19

func IsSubPath(parent, child string) (isSub bool, err error)

IsSubPath child是否是parent子路径 IsSubPath("/a/b", "/a/b/c")

func IsTrue added in v0.0.2

func IsTrue(v interface{}) (res bool)

IsTrue 是否为真 判断是true、"true"、1、"1" @param v interface{} "传入任意值" @return bool IsTrue(arg)

func JSONDecode added in v1.2.44

func JSONDecode(bs []byte, obj any) (err error)

func JSONDecodeByReader added in v1.2.45

func JSONDecodeByReader(reader io.Reader, obj any) (err error)

func JSONDecodeUseNumber added in v0.3.1

func JSONDecodeUseNumber(bs []byte, obj any) (err error)

func JSONEncoderByWriter added in v1.2.45

func JSONEncoderByWriter(writer io.Writer, obj any) (err error)

func JsonBytesToObj added in v1.2.45

func JsonBytesToObj(bs []byte, obj any) (err error)

func JsonToMap added in v0.5.7

func JsonToMap(str string) (res map[string]any, err error)

JsonToMap json 字符串 转 map对象 JsonToMap("{\"a\":1}")

func JsonToObj added in v0.5.7

func JsonToObj(str string, obj any) (err error)

JsonToObj json 字符串 转 对象 JsonToObj("{\"a\":1}", &obj)

func LoadDirFilenames added in v0.0.2

func LoadDirFilenames(dir string) (filenames []string, err error)

LoadDirFilenames 加载目录下文件(文件名为相对路径) LoadDirFilenames("/x/x/xxx\xx\xx")

func LoadDirFiles added in v0.0.2

func LoadDirFiles(dir string) (fileMap map[string][]byte, err error)

LoadDirFiles 加载目录下文件 读取文件内容(key为文件名为相对路径) LoadDirFiles("/x/x/xxx\xx\xx")

func LockByKey added in v0.0.2

func LockByKey(key string)

LockByKey 根据Key进行同步锁 LockByKey("user:1")

func Marshal added in v0.0.7

func Marshal(name string) string

Marshal 转换为大驼峰命名法则 首字母大写,“_” 忽略后大写 Marshal("abc_def")

func MilliToTimeText added in v1.2.7

func MilliToTimeText(milli int64) (v string)

MilliToTimeText 将 毫秒 转为 'xx天xx时xx分xx秒xx毫秒'

func NewDefaultLogger added in v0.7.1

func NewDefaultLogger() *zap.Logger

func NewHttpClient added in v1.2.23

func NewHttpClient() *http.Client

func NewLocker added in v0.5.7

func NewLocker() sync.Locker

NewLocker 创建 Mutex Locker obj = NewLocker() obj.Lock() obj.Unlock()

func NewLoggerByCallerSkip added in v0.7.1

func NewLoggerByCallerSkip(skip int) *zap.Logger

NewLoggerByCallerSkip 跳过的调用方数量 skip = 1 表示 输出的 文件名 行号等 为上层方法

func NewWaitGroup added in v0.5.7

func NewWaitGroup() *sync.WaitGroup

NewWaitGroup 创建 WaitGroup , obj = NewWaitGroup() obj.Add(1) obj.Done() obj.Wait()

func NextId added in v1.0.6

func NextId() int64

NextId 新建一个ID生成器,传入生成器ID NextId() 获取一个 雪花片算法的 ID 其中 workerId 为 默认 0

func ObjToJson added in v0.5.7

func ObjToJson(obj any) (res string, err error)

ObjToJson 对象 转 json 字符串 ObjToJson(obj)

func ObjToJsonBytes added in v1.2.43

func ObjToJsonBytes(obj any) (bs []byte, err error)

ObjToJsonBytes 对象 转 json Buffer ObjToJsonBytes(obj)

func ObjToMarshalIndent added in v1.2.45

func ObjToMarshalIndent(obj any, prefix string, indent string) (bs []byte, err error)

ObjToMarshalIndent 对象 转 json Buffer ObjToMarshalIndent(obj)

func ObjToObjByJson added in v1.2.43

func ObjToObjByJson(obj any, toObj any) (err error)

func PKCS5Padding added in v0.0.2

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding added in v0.0.2

func PKCS5UnPadding(origData []byte) []byte

func PathExists added in v0.0.2

func PathExists(path string) (bool, error)

PathExists 路径文件是否存在 PathExists("/x/x/xxx\xx\xx")

func PostForm added in v1.2.23

func PostForm[T any](url string, data url.Values, response T) (res T, body string, err error)

func PostFormBytes added in v1.2.23

func PostFormBytes(url string, data url.Values) (res []byte, err error)

func PostFormHeader added in v1.2.23

func PostFormHeader[T any](url string, header http.Header, data url.Values, response T) (res T, body string, err error)

func PostJson added in v1.2.23

func PostJson[T any](url string, data any, response T) (res T, body string, err error)

func PostJsonHeader added in v1.2.23

func PostJsonHeader[T any](url string, header http.Header, data any, response T) (res T, body string, err error)

func RandomInt added in v0.0.2

func RandomInt(min int, max int) (res int)

RandomInt 获取随机数 @param min int "最小值" @param max int "最大值" @return int "随机数" RandomInt(1, 10)

func RandomInt64 added in v0.0.2

func RandomInt64(min int64, max int64) (res int64)

RandomInt64 获取随机数 @param min int64 "最小值" @param max int64 "最大值" @return int64 "随机数" RandomInt64(1, 10)

func RandomString added in v0.0.2

func RandomString(minLen int, maxLen int) (res string)

RandomString 获取随机字符串 @param minLen int "最小长度" @param maxLen int "最大长度" @return string RandomString(2, 20)

func RandomUserName added in v0.0.2

func RandomUserName(size int) (res string)

RandomUserName 随机姓名 @param size int "名长度" @return string RandomUserName(2)

func Read added in v0.0.2

func Read(reader io.Reader, buf []byte, onRead func(n int) (err error)) (err error)

func ReadByFunc added in v0.0.2

func ReadByFunc(read func(p []byte) (n int, err error), buf []byte, onRead func(n int) (err error)) (err error)

func ReadFile added in v0.0.2

func ReadFile(filename string) (bs []byte, err error)

ReadFile 读取文件内容 返回 []byte ReadFile("/x/x/xxx\xx\xx")

func ReadFileString added in v0.0.4

func ReadFileString(filename string) (str string, err error)

ReadFileString 读取文件内容 返回字符串 ReadFileString("/x/x/xxx\xx\xx")

func ReadLine added in v0.0.2

func ReadLine(filename string) (lines []string, err error)

ReadLine 逐行读取文件 ReadLine("/x/x/xxx\xx\xx")

func RsaDecrypt added in v0.0.3

func RsaDecrypt(ciphertext []byte, privateKey []byte) ([]byte, error)

func RsaDecryptByKey added in v0.0.3

func RsaDecryptByKey(decrypt string, privateKey string) (res string, err error)

RsaDecryptByKey RSA解密 RsaDecryptByKey("这是加密后的文本", "这是密钥")

func RsaEncrypt added in v0.0.3

func RsaEncrypt(origData []byte, publicKey []byte) ([]byte, error)

func RsaEncryptByKey added in v0.0.3

func RsaEncryptByKey(origData string, publicKey string) (res string, err error)

RsaEncryptByKey RSA加密,返回 base64 字符 RsaEncryptByKey("这是需要加密的文本", "这是密钥")

func SetIdWorker added in v1.2.15

func SetIdWorker(worker *IdWorker)

func SetTempDir added in v0.0.7

func SetTempDir(dir string)

func StrPadLeft added in v0.5.7

func StrPadLeft(input string, padLength int, padString string) string

StrPadLeft 在字符串 左侧补全 字符串 到 指定长度 input string 原字符串 padLength int 规定补齐后的字符串长度 padString string 自定义填充字符串 StrPadLeft("xx", 5, "0") 左侧补”0“达到5位长度

func StrPadRight added in v0.5.7

func StrPadRight(input string, padLength int, padString string) string

StrPadRight 在字符串 右侧补全 字符串 到 指定长度 input string 原字符串 padLength int 规定补齐后的字符串长度 padString string 自定义填充字符串 StrPadRight("xx", 5, "0") 右侧补”0“达到5位长度

func StringIndexOf added in v0.0.2

func StringIndexOf(array []string, v string) (index int)

StringIndexOf 返回 某个值 在数组中的索引位置,未找到返回 -1 StringIndexOf(["a", "b", "c"], "d")

func StringJoin added in v1.2.32

func StringJoin(es []string, sep string) string

StringJoin 字符串拼接

func StringTo added in v1.2.18

func StringTo[T any](str string) (res T, err error)

func StringToBytes added in v0.5.9

func StringToBytes(str string) []byte

StringToBytes 字符串转为 []byte StringToBytes("这是文本")

func StringToFloat64 added in v0.4.6

func StringToFloat64(str string) float64

StringToFloat64 字符串转 float64 StringToFloat64("11.2")

func StringToInt added in v0.4.6

func StringToInt(str string) int

StringToInt 字符串转 int StringToInt("11")

func StringToInt64 added in v0.4.6

func StringToInt64(str string) int64

StringToInt64 字符串转 int64 StringToInt64("11")

func StringToUint64 added in v1.1.7

func StringToUint64(str string) uint64

StringToUint64 字符串转 uint64 StringToUint64("11")

func SumToString added in v0.7.2

func SumToString(nums ...interface{}) string

SumToString 将任意数相加,为防止精度丢失,可以传入数字字符串 SumToString("4611686027042965191", 11)

func TimeFormat added in v0.0.2

func TimeFormat(v time.Time, layout string) string

TimeFormat 时间格式化 默认 "2006-01-02 15:04:05" @param v time.Time "时间" @param layout string "格式化字符串,默认使用"2006-01-02 15:04:05"" TimeFormat(time, "2006-01-02 15:04:05")

func To added in v1.2.16

func To[T any](from any) (res T)

func TrimLeft added in v1.2.30

func TrimLeft(arg string, trim string) string

TrimLeft 去除 所有 匹配的 前缀

func TrimPrefix added in v1.2.30

func TrimPrefix(arg string, trim string) string

TrimPrefix 去除 匹配的 前缀

func TrimRight added in v1.2.30

func TrimRight(arg string, trim string) string

TrimRight 去除 所有 匹配的 后缀

func TrimSpace added in v1.2.30

func TrimSpace(arg string) string

TrimSpace 去除 前后空格

func TrimSuffix added in v1.2.30

func TrimSuffix(arg string, trim string) string

TrimSuffix 去除 匹配的 后缀

func UnGzipBytes added in v0.0.3

func UnGzipBytes(data []byte) ([]byte, error)

UnGzipBytes 解压

func UnZip added in v0.0.3

func UnZip(zipFile string, destDir string) error

UnZip zip解压 zipFile 压缩包地址 destDir 解压保存文件夹

func UnlockByKey added in v0.0.2

func UnlockByKey(key string)

UnlockByKey 根据Key进行解锁同步锁 UnlockByKey("user:1")

func ValueToFloat64 added in v1.2.16

func ValueToFloat64(value any) (res float64, err error)

ValueToFloat64 值 转 float64 ValueToFloat64("11")

func ValueToInt64 added in v1.2.16

func ValueToInt64(value any) (res int64, err error)

ValueToInt64 值 转 int64 ValueToInt64("11")

func ValueToUint64 added in v1.2.16

func ValueToUint64(value any) (res uint64, err error)

ValueToUint64 值 转 uint64 ValueToUint64("11")

func Write added in v0.0.2

func Write(writer io.Writer, buf []byte, onWrite func(n int) (err error)) (err error)

func WriteFile added in v0.0.2

func WriteFile(filename string, bs []byte) (err error)

WriteFile 写入文件内容, WriteFile("/x/x/xxx\xx\xx", StringToBytes("这是文本"))

func WriteFileString added in v0.0.4

func WriteFileString(filename string, str string) (err error)

WriteFileString 写入文件内容 WriteFileString("/x/x/xxx\xx\xx", "这是文本")

func Zip added in v0.0.2

func Zip(srcFile string, destZip string) error

Zip zip压缩 srcFile 文件路径,destZip压缩包保存路径

Types

type Cache added in v1.1.22

type Cache[K int | int64 | string, V any] struct {
	// contains filtered or unexported fields
}

Cache 临时缓存结构

func NewCache added in v1.1.22

func NewCache[K int | int64 | string, V any]() *Cache[K, V]

NewCache 创建 默认 缓存

func NewCacheByOptions added in v1.2.23

func NewCacheByOptions[K int | int64 | string, V any](opts *CacheOptions) *Cache[K, V]

NewCacheByOptions 创建一个 带策略的 缓存

func (*Cache[K, V]) Clear added in v1.1.22

func (this_ *Cache[K, V]) Clear()

Clear 清理

func (*Cache[K, V]) Get added in v1.1.22

func (this_ *Cache[K, V]) Get(key K) (res V, find bool)

Get 从缓存中获取一个项

func (*Cache[K, V]) GetAnRemove added in v1.2.23

func (this_ *Cache[K, V]) GetAnRemove(key K) (res V, find bool)

GetAnRemove 从缓存中获取一个项

func (*Cache[K, V]) GetOrLoad added in v1.2.23

func (this_ *Cache[K, V]) GetOrLoad(key K, load func() (V, error)) (res V, err error)

GetOrLoad 从缓存中获取一个项 如果没有 则调用 load 加载

func (*Cache[K, V]) Gets added in v1.2.47

func (this_ *Cache[K, V]) Gets(keys ...K) (res []V)

Gets 获取缓存多个项

func (*Cache[K, V]) ItemsSize added in v1.2.47

func (this_ *Cache[K, V]) ItemsSize() int

ItemsSize 缓存 数量

func (*Cache[K, V]) Put added in v1.1.22

func (this_ *Cache[K, V]) Put(key K, v V)

func (*Cache[K, V]) PutIfAbsent added in v1.1.22

func (this_ *Cache[K, V]) PutIfAbsent(key K, v V)

PutIfAbsent 不存在则新增

func (*Cache[K, V]) Remove added in v1.2.23

func (this_ *Cache[K, V]) Remove(key K)

Remove 清理 缓存

func (*Cache[K, V]) Removes added in v1.2.47

func (this_ *Cache[K, V]) Removes(keys ...K)

Removes 清理 缓存

func (*Cache[K, V]) Set added in v1.2.23

func (this_ *Cache[K, V]) Set(key K, value V)

Set 从缓存中获取一个项 如果没有 则调用 load 加载

func (*Cache[K, V]) SetOnRemoves added in v1.2.47

func (this_ *Cache[K, V]) SetOnRemoves(onRemoves func(isEvictionPolicy bool, items ...*CacheItem[K, V]))

func (*Cache[K, V]) Size added in v1.2.47

func (this_ *Cache[K, V]) Size() int

Size 缓存 数量

type CacheGroup added in v1.1.22

type CacheGroup[K int | int64 | string, V any] struct {
	// contains filtered or unexported fields
}

func NewCacheGroup added in v1.1.22

func NewCacheGroup[K int | int64 | string, V any](cacheSize uint) *CacheGroup[K, V]

func NewCacheGroupByOption added in v1.2.23

func NewCacheGroupByOption[K int | int64 | string, V any](cacheSize uint, opts *CacheOptions) *CacheGroup[K, V]

func (*CacheGroup[K, V]) Clear added in v1.1.22

func (this_ *CacheGroup[K, V]) Clear()

Clear 清理

func (*CacheGroup[K, V]) Get added in v1.1.22

func (this_ *CacheGroup[K, V]) Get(key K) (V, bool)

func (*CacheGroup[K, V]) GetCache added in v1.1.22

func (this_ *CacheGroup[K, V]) GetCache(key K) *Cache[K, V]

func (*CacheGroup[K, V]) GetCacheIndex added in v1.2.47

func (this_ *CacheGroup[K, V]) GetCacheIndex(key K) uint32

func (*CacheGroup[K, V]) GetKeyHashCode added in v1.2.47

func (this_ *CacheGroup[K, V]) GetKeyHashCode(key K) uint32

func (*CacheGroup[K, V]) GetStringHashCode added in v1.1.22

func (this_ *CacheGroup[K, V]) GetStringHashCode(str string) uint32

func (*CacheGroup[K, V]) Gets added in v1.2.47

func (this_ *CacheGroup[K, V]) Gets(keys ...K) (res []V)

Gets 获取缓存多个项

func (*CacheGroup[K, V]) ItemsSize added in v1.2.47

func (this_ *CacheGroup[K, V]) ItemsSize() (res int)

ItemsSize Items 数量

func (*CacheGroup[K, V]) Put added in v1.1.22

func (this_ *CacheGroup[K, V]) Put(key K, v V)

Put 设置值

func (*CacheGroup[K, V]) PutIfAbsent added in v1.1.22

func (this_ *CacheGroup[K, V]) PutIfAbsent(key K, v V)

PutIfAbsent 不存在则新增

func (*CacheGroup[K, V]) Remove added in v1.2.47

func (this_ *CacheGroup[K, V]) Remove(key K)

Remove 删除

func (*CacheGroup[K, V]) Removes added in v1.2.47

func (this_ *CacheGroup[K, V]) Removes(keys ...K)

Removes 删除

func (*CacheGroup[K, V]) SetGetCacheIndex added in v1.2.47

func (this_ *CacheGroup[K, V]) SetGetCacheIndex(getCacheIndex func(key K) uint32)

func (*CacheGroup[K, V]) SetOnRemoves added in v1.2.47

func (this_ *CacheGroup[K, V]) SetOnRemoves(onRemoves func(isEvictionPolicy bool, items ...*CacheItem[K, V]))

func (*CacheGroup[K, V]) Size added in v1.2.47

func (this_ *CacheGroup[K, V]) Size() (res int)

Size 数量

type CacheItem added in v1.2.23

type CacheItem[K int | int64 | string, V any] struct {
	Key         K
	Value       V
	WriteAt     int64  // 写入 时间 毫秒
	AccessAt    int64  // 访问 时间 毫秒
	AccessCount uint64 // 访问 次数
	Index       uint64 // 加入的顺序索引
}

CacheItem 缓存项结构

type CacheOptions added in v1.2.23

type CacheOptions struct {
	// 缓存池大小,在缓存数量到达该大小时, 开始回收旧的数据
	MaximumSize int
	// 缓存 一段时间 未使用 从内存中删除  单位 毫秒
	ExpireAfterAccess int64
	// 缓存 在写入 一段时间后 不管 有没有使用 强制删除  单位 毫秒
	ExpireAfterWrite int64
	// 淘汰策略 定时器 设置 多长时间执行一次  默认 1 分钟
	EvictionPolicyTimer time.Duration
}

type DirFileInfo added in v1.1.20

type DirFileInfo struct {
	Path     string `json:"path"`
	Name     string `json:"name"`
	FileSize int64  `json:"fileSize"`
}

type DirInfo added in v1.1.20

type DirInfo struct {
	Path          string         `json:"path"`
	Name          string         `json:"name"`
	FileSize      int64          `json:"fileSize,omitempty"`
	AllFileSize   int64          `json:"allFileSize,omitempty"`
	DirNumber     int            `json:"dirNumber,omitempty"`
	FileNumber    int            `json:"fileNumber,omitempty"`
	AllFileNumber int            `json:"allFileNumber,omitempty"`
	AllDirNumber  int            `json:"allDirNumber,omitempty"`
	FileInfos     []*DirFileInfo `json:"fileInfos,omitempty"`
	DirInfos      []*DirInfo     `json:"dirInfos,omitempty"`
}

func LoadDirInfo added in v1.1.20

func LoadDirInfo(dir string, loadSubDir bool) (dirInfo *DirInfo, err error)

LoadDirInfo 加载目录信息,目录下文件目录数量大小等,可以配置加载所有子目录 LoadDirInfo("/x/x/", true)

type FieldInfo added in v1.2.29

type FieldInfo struct {
	Name   string `json:"name,omitempty"`
	Index  int    `json:"index,omitempty"`
	Column string `json:"column,omitempty"`
	Json   string `json:"json,omitempty"`
	Bson   string `json:"bson,omitempty"`
	Xml    string `json:"xml,omitempty"`
	Yaml   string `json:"yaml,omitempty"`
	Toml   string `json:"toml,omitempty"`

	IsString bool `json:"isString,omitempty"`
	IsNumber bool `json:"isNumber,omitempty"`
	IsBool   bool `json:"isBool,omitempty"`
	IsStruct bool `json:"isStruct,omitempty"`
	IsMap    bool `json:"isMap,omitempty"`
	IsList   bool `json:"isList,omitempty"`

	StructType reflect.Type `json:"structType,omitempty"`

	Extend any `json:"extend,omitempty"`
	// contains filtered or unexported fields
}

func GetMapFields added in v1.2.28

func GetMapFields(v any) (fields []*FieldInfo)

func (*FieldInfo) GetStructField added in v1.2.29

func (this_ *FieldInfo) GetStructField() reflect.StructField

func (*FieldInfo) GetValue added in v1.2.29

func (this_ *FieldInfo) GetValue() reflect.Value

type HashRing added in v1.2.16

type HashRing[T any] struct {
	Hash func(s string) uint32
	// contains filtered or unexported fields
}

HashRing 哈希环 存放 Node

func NewHashRing added in v1.2.16

func NewHashRing[T any](virtualNodeSize int, obj T) *HashRing[T]

NewHashRing 创建 哈希环 指定 虚拟节点数量 默认使用 DefaultVirtualNodeSize

func (*HashRing[T]) AddNode added in v1.2.16

func (h *HashRing[T]) AddNode(node *HashRingNode[T])

AddNode add node to hash ring

func (*HashRing[T]) AddNodes added in v1.2.16

func (h *HashRing[T]) AddNodes(nodes []*HashRingNode[T])

AddNodes add nodes to hash ring

func (*HashRing[T]) GetHash added in v1.2.16

func (h *HashRing[T]) GetHash(s string) (res uint32)

func (*HashRing[T]) GetNode added in v1.2.16

func (h *HashRing[T]) GetNode(s string) (node *HashRingVirtualNode[T])

GetNode get node with key

func (*HashRing[T]) RemoveNode added in v1.2.16

func (h *HashRing[T]) RemoveNode(node *HashRingNode[T])

RemoveNode remove node

func (*HashRing[T]) UpdateNode added in v1.2.16

func (h *HashRing[T]) UpdateNode(node *HashRingNode[T])

UpdateNode update node with weight

type HashRingNode added in v1.2.16

type HashRingNode[T any] struct {
	// contains filtered or unexported fields
}

func NewHashRingNode added in v1.2.16

func NewHashRingNode[T any](nodeKey string, obj T, weight int) *HashRingNode[T]

NewHashRingNode 创建 一个 哈希环 节点

func (*HashRingNode[T]) GetNode added in v1.2.16

func (this_ *HashRingNode[T]) GetNode() (res T)

type HashRingVirtualNode added in v1.2.16

type HashRingVirtualNode[T any] struct {
	// contains filtered or unexported fields
}

type ICache added in v1.2.47

type ICache[K int | int64 | string, V any] interface {
	Get(key K) (res V, find bool)
	Gets(keys ...K) (res []V)
	PutIfAbsent(key string, v V)
	Put(key K, v V)
	Remove(key K)
	Removes(keys ...K)
	Size() int
	ItemsSize() int
}

type IdWorker added in v1.0.6

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

func NewIdWorker added in v1.0.6

func NewIdWorker(workerId int64) (*IdWorker, error)

NewIdWorker 新建一个 雪花片算法 ID生成器,传入生成器ID NewIdWorker(1)

func (*IdWorker) NextId added in v1.0.6

func (w *IdWorker) NextId() int64

type SSHChanConn added in v0.4.4

type SSHChanConn struct {
	Conn net.Conn
}

func (*SSHChanConn) Close added in v0.4.4

func (t *SSHChanConn) Close() error

func (*SSHChanConn) LocalAddr added in v0.4.4

func (t *SSHChanConn) LocalAddr() net.Addr

func (*SSHChanConn) Read added in v0.4.4

func (t *SSHChanConn) Read(b []byte) (n int, err error)

func (*SSHChanConn) RemoteAddr added in v0.4.4

func (t *SSHChanConn) RemoteAddr() net.Addr

func (*SSHChanConn) SetDeadline added in v0.4.4

func (t *SSHChanConn) SetDeadline(deadline time.Time) error

func (*SSHChanConn) SetReadDeadline added in v0.4.4

func (t *SSHChanConn) SetReadDeadline(deadline time.Time) error

func (*SSHChanConn) SetWriteDeadline added in v0.4.4

func (t *SSHChanConn) SetWriteDeadline(deadline time.Time) error

func (*SSHChanConn) Write added in v0.4.4

func (t *SSHChanConn) Write(b []byte) (n int, err error)

type StringSort added in v0.3.8

type StringSort interface {
	GetName() string
}

type StringSortList added in v0.3.8

type StringSortList []StringSort

func (StringSortList) Len added in v0.3.8

func (m StringSortList) Len() int

Len 实现sort.Interface接口的获取元素数量方法

func (StringSortList) Less added in v0.3.8

func (m StringSortList) Less(i, j int) bool

Less 实现 sort.Interface 接口的比较元素方法

func (StringSortList) Swap added in v0.3.8

func (m StringSortList) Swap(i, j int)

Swap 实现sort.Interface接口的交换元素方法

type StructCache added in v1.2.28

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

func NewStructCache added in v1.2.28

func NewStructCache() *StructCache

func (*StructCache) GetStructInfo added in v1.2.28

func (this_ *StructCache) GetStructInfo(structType reflect.Type) (info *StructInfo)

type StructInfo added in v1.2.28

type StructInfo struct {
	IsMap    bool         `json:"isMap,omitempty"`
	IsList   bool         `json:"isList,omitempty"`
	IsStruct bool         `json:"isStruct,omitempty"`
	Type     reflect.Type `json:"type,omitempty"`
	Fields   []*FieldInfo `json:"fields,omitempty"`

	NameMap   map[string]*FieldInfo `json:"nameMap,omitempty"`
	ColumnMap map[string]*FieldInfo `json:"columnMap,omitempty"`
	JsonMap   map[string]*FieldInfo `json:"jsonMap,omitempty"`
	BsonMap   map[string]*FieldInfo `json:"bsonMap,omitempty"`
	YamlMap   map[string]*FieldInfo `json:"yamlMap,omitempty"`
	XmlMap    map[string]*FieldInfo `json:"xmlMap,omitempty"`
	TomlMap   map[string]*FieldInfo `json:"tomlMap,omitempty"`
	KeyMap    map[string]*FieldInfo `json:"keyMap,omitempty"`

	Extend any `json:"extend,omitempty"`
}

func CreateStructInfo added in v1.2.28

func CreateStructInfo(structType reflect.Type) (info *StructInfo)

func (*StructInfo) Get added in v1.2.28

func (this_ *StructInfo) Get(key string) *FieldInfo

func (*StructInfo) GetFieldValue added in v1.2.28

func (this_ *StructInfo) GetFieldValue(data any, key string) (field *FieldInfo, fV reflect.Value, find bool)

func (*StructInfo) SetFieldValue added in v1.2.28

func (this_ *StructInfo) SetFieldValue(data any, name string, value any) (ok bool, err error)

type SyncMap added in v0.2.5

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

func NewSyncMap added in v0.2.5

func NewSyncMap() *SyncMap

func (*SyncMap) Clean added in v0.2.5

func (this_ *SyncMap) Clean()

func (*SyncMap) Get added in v0.2.5

func (this_ *SyncMap) Get(key interface{}) interface{}

func (*SyncMap) Len added in v0.2.5

func (this_ *SyncMap) Len() int

func (*SyncMap) Set added in v0.2.5

func (this_ *SyncMap) Set(key interface{}, value interface{})

Jump to

Keyboard shortcuts

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