util

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 32 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

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 (
	Logger = NewDefaultLogger()
)
View Source
var (
	RandForRandomInt = NewRandForRandom()
)

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 ArrayIndexOf added in v0.0.2

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

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

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 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 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 Int64IndexOf added in v0.0.2

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

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

func IntIndexOf added in v0.0.2

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

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

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 JSONDecodeUseNumber added in v0.3.1

func JSONDecodeUseNumber(bs []byte, obj interface{}) (err error)

func JsonToMap added in v0.5.7

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

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

func JsonToObj added in v0.5.7

func JsonToObj(str string, obj interface{}) (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 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 interface{}) (res string, err error)

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

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 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 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 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 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 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 struct {
	// contains filtered or unexported fields
}

func NewCache added in v1.1.22

func NewCache() *Cache

func (*Cache) Clear added in v1.1.22

func (this_ *Cache) Clear()

Clear 清理

func (*Cache) Delete added in v1.1.22

func (this_ *Cache) Delete(keys ...string)

Delete 删除

func (*Cache) Get added in v1.1.22

func (this_ *Cache) Get(key string) (interface{}, bool)

func (*Cache) Put added in v1.1.22

func (this_ *Cache) Put(key string, v interface{})

Put 设置值

func (*Cache) PutIfAbsent added in v1.1.22

func (this_ *Cache) PutIfAbsent(key string, v interface{})

PutIfAbsent 不存在则新增

type CacheGroup added in v1.1.22

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

func NewCacheGroup added in v1.1.22

func NewCacheGroup(cacheSize int) *CacheGroup

func (*CacheGroup) Clear added in v1.1.22

func (this_ *CacheGroup) Clear()

Clear 清理

func (*CacheGroup) Delete added in v1.1.22

func (this_ *CacheGroup) Delete(keys ...string)

Delete 删除

func (*CacheGroup) Get added in v1.1.22

func (this_ *CacheGroup) Get(key string) (interface{}, bool)

func (*CacheGroup) GetCache added in v1.1.22

func (this_ *CacheGroup) GetCache(key string) *Cache

func (*CacheGroup) GetCacheByHash added in v1.1.22

func (this_ *CacheGroup) GetCacheByHash(hashCode uint32) *Cache

func (*CacheGroup) GetStringHashCode added in v1.1.22

func (this_ *CacheGroup) GetStringHashCode(str string) uint32

func (*CacheGroup) Put added in v1.1.22

func (this_ *CacheGroup) Put(key string, v interface{})

Put 设置值

func (*CacheGroup) PutIfAbsent added in v1.1.22

func (this_ *CacheGroup) PutIfAbsent(key string, v interface{})

PutIfAbsent 不存在则新增

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 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 RandForRandom added in v0.6.9

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

func NewRandForRandom added in v0.6.9

func NewRandForRandom() *RandForRandom

func (*RandForRandom) RandomInt added in v0.6.9

func (this_ *RandForRandom) RandomInt(min int, max int) (res int)

func (*RandForRandom) RandomInt64 added in v0.6.9

func (this_ *RandForRandom) RandomInt64(min int64, max int64) (res 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 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