utils

package module
v0.0.0-...-f242dd8 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

README

gUtil

一个通用 的go utils 类库, 包含常用的各种 go 操作, 避免重复造轮子 常用的包括 文件 压缩 日期 定时器 时间轮 加密解密 curl访问 等

Documentation

Index

Constants

View Source
const (
	ConfigEnv  = "GVA_CONFIG"
	ConfigFile = "config.yaml"
)
View Source
const (
	KC_RAND_KIND_NUM   = 0 // 纯数字
	KC_RAND_KIND_LOWER = 1 // 小写字母
	KC_RAND_KIND_UPPER = 2 // 大写字母
	KC_RAND_KIND_ALL   = 3 // 数字、大小写字母
)

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired")
	TokenNotValidYet = errors.New("Token not active yet")
	TokenMalformed   = errors.New("That's not even a token")
	TokenInvalid     = errors.New("Couldn't handle this token:")
)
View Source
var (
	IdVerify           = Rules{"ID": {NotEmpty()}}
	ApiVerify          = Rules{"Path": {NotEmpty()}, "Description": {NotEmpty()}, "ApiGroup": {NotEmpty()}, "Method": {NotEmpty()}}
	MenuVerify         = Rules{"Path": {NotEmpty()}, "ParentId": {NotEmpty()}, "Name": {NotEmpty()}, "Component": {NotEmpty()}, "Sort": {Ge("0")}}
	MenuMetaVerify     = Rules{"Title": {NotEmpty()}}
	LoginVerify        = Rules{"CaptchaId": {NotEmpty()}, "Captcha": {NotEmpty()}, "Username": {NotEmpty()}, "Password": {NotEmpty()}}
	RegisterVerify     = Rules{"Username": {NotEmpty()}, "NickName": {NotEmpty()}, "Password": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
	PageInfoVerify     = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
	CustomerVerify     = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
	SuperBuilderVerify = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
	AuthorityVerify    = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}}
	//AuthorityVerify        = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}, "ParentId": {NotEmpty()}}
	AuthorityIdVerify      = Rules{"AuthorityId": {NotEmpty()}}
	OldAuthorityVerify     = Rules{"OldAuthorityId": {NotEmpty()}}
	ChangePasswordVerify   = Rules{"Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
	SetUserAuthorityVerify = Rules{"AuthorityId": {NotEmpty()}}
)
View Source
var CustomizeMap = make(map[string]Rules)

Functions

func AecDecode

func AecDecode(str string, key string) string

aec 解密

func AecEncode

func AecEncode(str string, key string) string

aec 加密

func ArrayToString

func ArrayToString(array []interface{}) string

func AutoClearCode

func AutoClearCode(filepath string, codeData string) error

func AutoInjectionCode

func AutoInjectionCode(filepath string, funcName string, codeData string) error

func BreakPointContinue

func BreakPointContinue(content []byte, fileName string, contentNumber int, contentTotal int, fileMd5 string) (error, string)

func CheckMd5

func CheckMd5(content []byte, chunkMd5 string) (CanUpload bool)

func ClearTable

func ClearTable(db *gorm.DB, tableName string, compareField string, interval string) error

func CreateDir

func CreateDir(dirs ...string) (err error)

func CreateFile

func CreateFile(name string) (*os.File, error)

func DeLFile

func DeLFile(filePath string) error

func Des3Decode

func Des3Decode(str string, key string) string

3des 解密 ToBase64String

func Des3Encode

func Des3Encode(str string, key string) string

3des 加密 ToBase64String

func DownloadFile

func DownloadFile(url string, localPath string, filename string) (fullPath string, err error)

func Eq

func Eq(mark string) string

func ExecShell

func ExecShell(s string) (string, error)

阻塞式的执行外部shell命令的函数,等待执行完毕并返回标准输出

func FileExist

func FileExist(path string) bool

FileExist 判断文件是否存在

func FileExists

func FileExists(path string) bool

func FileMove

func FileMove(src string, dst string) (err error)

func GUID

func GUID() string

func Ge

func Ge(mark string) string

func GetIp

func GetIp() string

func GetType

func GetType(params interface{}) string

GetType : 获取数据类型字符串 (string, int, float64, []int, []string, map[string]int ...) GetType : (能不用则不用,由于涉及到使用reflect包,性能堪忧)

func GetUserAuthorityId

func GetUserAuthorityId(c *gin.Context) string

从Gin的Context中获取从jwt解析出来的用户角色id

func GetUserID

func GetUserID(c *gin.Context) int64

从Gin的Context中获取从jwt解析出来的用户ID

func GetUserInfo

func GetUserInfo(c *gin.Context) *systemReq.CustomClaims

从Gin的Context中获取从jwt解析出来的用户角色id

func GetUserUuid

func GetUserUuid(c *gin.Context) uuid.UUID

从Gin的Context中获取从jwt解析出来的用户UUID

func GetWriteSyncer

func GetWriteSyncer(file string) zapcore.WriteSyncer

func Gt

func Gt(mark string) string

func Gz

func Gz(files []*os.File, dest string) error

下面是 gz 文件操作------------------------------------------------------------------------------ 压缩 使用gzip压缩成tar.gz

func InArray

func InArray(needle interface{}, hystack interface{}) bool

InArray :给定元素值 是否在 指定的数组中

func Int2Time

func Int2Time(ts int64) *time.Time

numToTime 时间戳转time ,注意是否纳秒

func IntPtr

func IntPtr(s int) *int

转为string指针

func Ip2long

func Ip2long(ipstr string) (ip uint32)

func IsEmpty

func IsEmpty(params interface{}) bool

判断是否为空 0, nil ,"", 空数组 = true

func IsEmptyStr

func IsEmptyStr(params string) bool

空字符串 返回true 否则返回 false

func IsFileExist

func IsFileExist(filename string, filesize int64) bool

func Krand

func Krand(size int, kind int) string

随机字符串

func Le

func Le(mark string) string

func Long2ip

func Long2ip(ip uint32) string

func Lt

func Lt(mark string) string

func MD5V

func MD5V(str []byte, b ...byte) string

func MakeFile

func MakeFile(fileName string, FileMd5 string) (error, string)

func Md5ByBytes

func Md5ByBytes(b []byte) string

func Md5ByString

func Md5ByString(str string) string

* md5 加密方式 *

func Ne

func Ne(mark string) string

func NotEmpty

func NotEmpty() string

func PathExists

func PathExists(path string) (bool, error)

func RegexpMatch

func RegexpMatch(rule string) string

@author: [zooqkl](https://github.com/zooqkl) @function: RegexpMatch @description: 正则校验 校验输入项是否满足正则表达式 @param: rule string @return: string

func RegisterRule

func RegisterRule(key string, rule Rules) (err error)

func Reload

func Reload() error

func RemoveChunk

func RemoveChunk(FileMd5 string) error

func Str2Time

func Str2Time(str string) *time.Time

StrToTime 字符串转time

func StrToInt

func StrToInt(str string) int

StrToInt string 转int

func StrToInt64

func StrToInt64(str string) int64

StrToInt string 转int64

func StrToUInt

func StrToUInt(str string) uint

StrToUInt string 转uint

func Strct2Slice

func Strct2Slice(f interface{}, sheetFieldsJson []string) []interface{}

struct 转 切片

func StringPtr

func StringPtr(s string) *string

转为int指针

func StructToMap

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

func Ternary

func Ternary(a bool, b, c interface{}) interface{}

三目运算函数

func TimeSub

func TimeSub(t1, t2 time.Time) int

Truncate方法用的是绝对时间,如果给出的时间为本地时间,会存在时区,会出现不同时间化为同一天的情况 两个日期间相差多少天,两个不同日期的,相差一秒都算一天 https://www.jianshu.com/p/b2efbe971105

func TimeToStr

func TimeToStr(t *time.Time) string

获取 20160102150405 格式

func TrimSpace

func TrimSpace(target interface{})

func UUID

func UUID() string

32位

func UUID36

func UUID36() string

f5394eef-e576-4709-9e4b-a7c231bd34a4

func UnGz

func UnGz(tarFile, dest string) error

解压 tar.gz

func Unzip

func Unzip(zipFile string, destDir string) error

解压缩 (只能是zip 文件 gz不行)

func Unzip_tx

func Unzip_tx(tarFile, dest string) (path string, err error)

解压 tarFile 源文件 ,dest 解压目录

func UrlQueryStrToMap

func UrlQueryStrToMap(urlstr string) (map[string]interface{}, error)

func Verify

func Verify(st interface{}, roleMap Rules) (err error)

func Zip

func Zip(srcFile string, destZip string) error

压缩 (只能是zip 文件 gz不行) srcFile could be a single file or a directory

func ZipFiles

func ZipFiles(filename string, files []string, oldForm, newForm string) error

Types

type ExcelHelper

type ExcelHelper struct {
}

func (*ExcelHelper) ParseExcel2InfoList

func (exa *ExcelHelper) ParseExcel2InfoList() ([]system.SysBaseMenu, error)

func (*ExcelHelper) ParseInfoList2Excel

func (exa *ExcelHelper) ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims request.CustomClaims) (string, error)

创建一个token

func (*JWT) CreateTokenByOldToken

func (j *JWT) CreateTokenByOldToken(oldToken string, claims request.CustomClaims) (string, error)

CreateTokenByOldToken 旧token 换新token 使用归并回源避免并发问题

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*request.CustomClaims, error)

解析 token

type Rules

type Rules map[string][]string

type RulesMap

type RulesMap map[string]Rules

Directories

Path Synopsis
Package unpackit allows you to easily unpack *.tar.gz, *.tar.bzip2, *.tar.xz, *.zip and *.tar files.
Package unpackit allows you to easily unpack *.tar.gz, *.tar.bzip2, *.tar.xz, *.zip and *.tar files.

Jump to

Keyboard shortcuts

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