util

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 31 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 *zap.Logger
)
View Source
var (
	// RandForRandomInt 设置随机数种子
	RandForRandomInt = rand.New(rand.NewSource(time.Now().UnixNano()))
)

Functions

func AesCBCDecrypt added in v0.0.2

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

AesCBCDecrypt CBC模式解密

func AesCBCEncrypt added in v0.0.2

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

AesCBCEncrypt CBC模式加密

func AesDecryptCBCByKey added in v0.0.2

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

AesDecryptCBCByKey AES解密,CBC

func AesDecryptECBByKey added in v0.0.2

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

AesDecryptECBByKey AES解密,ECB

func AesECBDecrypt added in v0.0.2

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

AesECBDecrypt ECB模式解密

func AesECBEncrypt added in v0.0.2

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

AesECBEncrypt ECB模式加密

func AesEncryptCBCByKey added in v0.0.2

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

AesEncryptCBCByKey AES加密,CBC

func AesEncryptECBByKey added in v0.0.2

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

AesEncryptECBByKey AES加密,ECB

func ArrayIndexOf added in v0.0.2

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

ArrayIndexOf 返回 某个值 在数组中的索引位置,未找到返回 -1

func FirstToLower added in v0.0.2

func FirstToLower(str string) (res string)

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

func FirstToUpper added in v0.0.2

func FirstToUpper(str string) (res string)

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

func FormatPath added in v0.0.2

func FormatPath(path string) string

FormatPath 格式化路径

func GetAbsolutePath added in v0.0.2

func GetAbsolutePath(path string) (absolutePath string)

GetAbsolutePath 获取路径觉得路径

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 "时间"

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,如果不存在,则新建

func GetMD5 added in v0.0.3

func GetMD5(str string) string

GetMD5 获取MD5字符串 @param str string "需要MD5的字符串"

func GetNow added in v0.0.2

func GetNow() time.Time

GetNow 获取当前时间

func GetNowFormat added in v0.0.2

func GetNowFormat() string

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

func GetNowSecond added in v0.0.2

func GetNowSecond() int64

GetNowSecond 获取当前时间戳 到秒

func GetNowTime

func GetNowTime() int64

GetNowTime 获取当前时间戳 到毫秒

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 "时间"

func GetStringValue added in v0.0.2

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

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

func GetTempDir added in v0.0.7

func GetTempDir() (dir string, err error)

GetTempDir 获取临时目录

func GetTimeByTime added in v0.0.2

func GetTimeByTime(v time.Time) int64

GetTimeByTime 获取时间戳 到毫秒 @param v time.Time "时间"

func GetUUID added in v0.0.3

func GetUUID() (res string)

GetUUID 生成UUID

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

func IntIndexOf added in v0.0.2

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

IntIndexOf 返回 某个值 在数组中的索引位置,未找到返回 -1

func IsEmpty added in v0.0.2

func IsEmpty(v interface{}) bool

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

func IsFalse added in v0.0.2

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

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

func IsNotEmpty added in v0.0.2

func IsNotEmpty(v interface{}) bool

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

func IsTrue added in v0.0.2

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

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

func JSONDecodeUseNumber added in v0.3.1

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

func LoadDirFilenames added in v0.0.2

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

LoadDirFilenames 加载目录下文件(文件名为相对路径)

func LoadDirFiles added in v0.0.2

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

LoadDirFiles 加载目录下文件 读取文件内容(key为文件名为相对路径)

func LockByKey added in v0.0.2

func LockByKey(key string)

LockByKey 根据Key进行同步锁

func Marshal added in v0.0.7

func Marshal(name string) string

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

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 路径文件是否存在

func RandomInt added in v0.0.2

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

RandomInt 获取随机数 @param min int "最小值" @param max int "最大值" @return int "随机数"

func RandomInt64 added in v0.0.2

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

RandomInt64 获取随机数 @param min int64 "最小值" @param max int64 "最大值" @return int64 "随机数"

func RandomString added in v0.0.2

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

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

func RandomUserName added in v0.0.2

func RandomUserName(size int) (res string)

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

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

func ReadFileString added in v0.0.4

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

ReadFileString 读取文件内容 返回字符串

func ReadLine added in v0.0.2

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

ReadLine 逐行读取文件

func RsaDecrypt added in v0.0.3

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

RsaDecrypt 解密

func RsaDecryptByKey added in v0.0.3

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

RsaDecryptByKey RSA解密

func RsaEncrypt added in v0.0.3

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

RsaEncrypt 加密

func RsaEncryptByKey added in v0.0.3

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

RsaEncryptByKey RSA加密

func SetTempDir added in v0.0.7

func SetTempDir(dir string)

SetTempDir 设置临时目录

func StringIndexOf added in v0.0.2

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

StringIndexOf 返回 某个值 在数组中的索引位置,未找到返回 -1

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`"

func ToPinYin added in v0.0.2

func ToPinYin(name string) (res string, err error)

ToPinYin 将姓名转为拼音 @param name string "姓名" @return string

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进行解锁同步锁

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 写入文件内容

func WriteFileString added in v0.0.4

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

WriteFileString 写入文件内容

func Zip added in v0.0.2

func Zip(srcFile string, destZip string) error

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

Types

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