utils

package
v0.0.0-...-cbb317a Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REGEX_COMMENT_VALUE = `comment:'(.*?)'`
	FIELD_JSON_VALUE    = "json"
	FIELD_GORM_VALUE    = "gorm"
)

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": []string{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()}, "Username": {NotEmpty()}, "Password": {NotEmpty()}}
	RegisterVerify       = Rules{"Username": {NotEmpty()}, "NickName": {NotEmpty()}, "Password": {NotEmpty()}, "RoleId": {NotEmpty()}}
	PageInfoVerify       = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
	CustomerVerify       = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
	AutoCodeVerify       = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
	AutoPackageVerify    = Rules{"PackageName": {NotEmpty()}}
	RoleVerify           = Rules{"RoleId": {NotEmpty()}, "RoleName": {NotEmpty()}}
	RoleIdVerify         = Rules{"RoleId": {NotEmpty()}}
	OldRoleVerify        = Rules{"OldRoleId": {NotEmpty()}}
	ChangePasswordVerify = Rules{"Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
	SetUserRoleVerify    = Rules{"RoleId": {NotEmpty()}}
)
View Source
var CustomizeMap = make(map[string]Rules)

Functions

func ArrayToString

func ArrayToString(array []interface{}) string

func BcryptCheck

func BcryptCheck(password, hash string) bool

func BcryptHash

func BcryptHash(password string) string

func BreakPointContinue

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

func CheckMd5

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

func CheckSpace

func CheckSpace(r rune) bool

func DbPing

func DbPing(dbType string, dsn string) error

func DeLFile

func DeLFile(filePath string) error

func Eq

func Eq(mark string) string

func EtcdGet

func EtcdGet(cli *clientv3.Client, key string) (*clientv3.GetResponse, error)

func EtcdPut

func EtcdPut(cli *clientv3.Client, key string, msg string) error

func FileExist

func FileExist(path string) bool

func FileMove

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

func FindDataLen

func FindDataLen(s string) (int, error)

func FindDataType

func FindDataType(s string) string

func FirstLower

func FirstLower(s string) string

func FirstUpper

func FirstUpper(s string) string

func Ge

func Ge(mark string) string

func GetStructFloat64Field

func GetStructFloat64Field(input interface{}, key string) (value float64, err error)

func GetStructStringField

func GetStructStringField(input interface{}, key string) (value string, err error)

func GetStructTagName

func GetStructTagName(i interface{}, fieldName string) []string

func GetStructTagNameRegex

func GetStructTagNameRegex(i interface{}, fieldName string, regStr string) []string

func GetUserID

func GetUserID(c *gin.Context, key string) uint

func GetUserRoleId

func GetUserRoleId(c *gin.Context, key string) uint

func GetUserUuid

func GetUserUuid(c *gin.Context, key string) uuid.UUID

func Gt

func Gt(mark string) string

func IntDif

func IntDif(int1, int2 []int) []int

func InterfaceToInt

func InterfaceToInt(v interface{}) (i int)

func Le

func Le(mark string) string

func Lt

func Lt(mark string) string

func MD5V

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

func MaheHump

func MaheHump(s string) string

func MakeFile

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

func Ne

func Ne(mark string) string

func NotEmpty

func NotEmpty() string

func ReadCsv

func ReadCsv(filePath string) (res [][]string, err error)

func ReadXls

func ReadXls(filePath string) (res [][]string, err error)

func ReadXlsx

func ReadXlsx(filePath string) (res [][]string, err error)

func RegexpMatch

func RegexpMatch(rule string) string

func RegisterRule

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

func RemoveChunk

func RemoveChunk(FileMd5 string) error

func StringDifference

func StringDifference(string1, string2 []string) []string

func StringIntersect

func StringIntersect(string1, string2 []string) []string

func StructToMap

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

func SubAfter

func SubAfter(s, sep, def string) string

func SubAfterLast

func SubAfterLast(s, sep, def string) string

func SubBefore

func SubBefore(s, sep, def string) string

func SubBeforeLast

func SubBeforeLast(s, sep, def string) string

func TrimBoth

func TrimBoth(s, trim string) string

func TrimEnd

func TrimEnd(s, trim string) string

func TrimSpace

func TrimSpace(target interface{})

func TrimStart

func TrimStart(s, trim string) string

func Unzip

func Unzip(zipFile string, destDir string) ([]string, error)

func ValidUTF8

func ValidUTF8(buf []byte) bool

func Verify

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

func ZipFiles

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

Types

type BaseClaims

type BaseClaims struct {
	UUID     uuid.UUID
	ID       uint
	Username string
	NickName string
	RoleId   uint
}

type CustomClaims

type CustomClaims struct {
	BaseClaims
	BufferTime int64
	jwt.RegisteredClaims
}

func GetClaims

func GetClaims(c *gin.Context, key string) (*CustomClaims, error)

func GetUserInfo

func GetUserInfo(c *gin.Context, key string) *CustomClaims

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT(key string) *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(baseClaims BaseClaims, bufferTime string, expiresTime string, issuer string) CustomClaims

func (*JWT) CreateToken

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

func (*JWT) CreateTokenByOldToken

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

func (*JWT) ParseToken

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

type Rules

type Rules map[string][]string

type RulesMap

type RulesMap map[string]Rules

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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