utils

package
v0.0.0-...-003a2e9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)

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()}, "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()}}
	AutoCodeVerify         = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
	AutoPackageVerify      = Rules{"PackageName": {NotEmpty()}}
	AuthorityVerify        = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {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 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 BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func BlankStringArrayToString

func BlankStringArrayToString(arr []string) (result string)

func BreakPointContinue

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

func Check

func Check(item []examManage.PaperTemplateItem) bool

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 CreateExamScore

func CreateExamScore(PlanDetail teachplan.ExamPlan, sum float64, studentId uint) (examScore examManage.ExamScore, err error)

func Crypto

func Crypto(str string) string

func DeLFile

func DeLFile(filePath string) error

func Decryption

func Decryption(str string) string

func DiffArray

func DiffArray(a []int64, b []int64) []int64

func Eq

func Eq(mark string) string

func ExecPapers

func ExecPapers(examPaperCommit examManage.CommitExamPaper) (err error)

func ExecProgram

func ExecProgram(program examManage.CommitProgram, score uint) (err error)

func FileExist

func FileExist(path string) bool

FileExist 判断文件是否存在

func FileMove

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

func GaSStudentsOfTeachClass

func GaSStudentsOfTeachClass(ids []uint) (students []uint, err error)

通过班级id查找将要考试或正在考试的同学,并将其记录在redis黑名单中

func Ge

func Ge(mark string) string

func GenerateQRCode

func GenerateQRCode(data string) string

func GetClaims

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

func GetCurrentAbPath

func GetCurrentAbPath() string

GetCurrentAbPath 获取项目路径

func GetDictionaryName

func GetDictionaryName(Type string, value int) (name string)

func GetLessonName

func GetLessonName(id int) string

func GetStudentClaims

func GetStudentClaims(c *gin.Context) (*systemReq.StudentCustomClaims, error)

func GetStudentId

func GetStudentId(c *gin.Context) uint

func GetStudentName

func GetStudentName(c *gin.Context) string

func GetTeachPlanName

func GetTeachPlanName(id uint) string

func GetTermName

func GetTermName(id uint) string

func GetUserAuthorityID

func GetUserAuthorityID(c *gin.Context) uint

func GetUserAuthorityId

func GetUserAuthorityId(c *gin.Context) uint

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

func GetUserID

func GetUserID(c *gin.Context) uint

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

func GetUserInfo

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

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

func GetUserUuid

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

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

func GetUuid

func GetUuid() string

func Gt

func Gt(mark string) string

func IntArrayToString

func IntArrayToString(array []int) (result string)

func IsExistInRedis

func IsExistInRedis(studentId uint) bool

判断某位学生是否在redis黑名单中

func Le

func Le(mark string) 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) (string, error)

func Ne

func Ne(mark string) string

func NotEmpty

func NotEmpty() string

func PathExists

func PathExists(path string) (bool, error)

func ReExecPapers

func ReExecPapers(sp teachplan.CoverRq) (err 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 SetStudentToRedis

func SetStudentToRedis(students []uint) error

func StringArrayToString

func StringArrayToString(arr []string) (result string)

func StringToStringArray

func StringToStringArray(strArr string, sep string) []string

字符串fenge

func StringToTime

func StringToTime(string2 string) time.Time

func StructToMap

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

func TimeToString

func TimeToString(t time.Time) string

func TrimSpace

func TrimSpace(target interface{})

func Unzip

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

解压

func Verify

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

func ZipFiles

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

Types

type Cpu

type Cpu struct {
	Cpus  []float64 `json:"cpus"`
	Cores int       `json:"cores"`
}

func InitCPU

func InitCPU() (c Cpu, err error)

type Disk

type Disk struct {
	UsedMB      int `json:"usedMb"`
	UsedGB      int `json:"usedGb"`
	TotalMB     int `json:"totalMb"`
	TotalGB     int `json:"totalGb"`
	UsedPercent int `json:"usedPercent"`
}

func InitDisk

func InitDisk() (d Disk, err error)

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(baseClaims request.BaseClaims) request.CustomClaims

func (*JWT) CreateStudentClaims

func (j *JWT) CreateStudentClaims(baseClaims request.StudentBaseClaims) request.StudentCustomClaims

func (*JWT) CreateStudentToken

func (j *JWT) CreateStudentToken(claims request.StudentCustomClaims) (string, error)

func (*JWT) CreateStudentTokenByOldToken

func (j *JWT) CreateStudentTokenByOldToken(oldToken string, claims request.StudentCustomClaims) (string, error)

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

func (*JWT) StudentParseToken

func (j *JWT) StudentParseToken(tokenString string) (*request.StudentCustomClaims, error)

type Os

type Os struct {
	GOOS         string `json:"goos"`
	NumCPU       int    `json:"numCpu"`
	Compiler     string `json:"compiler"`
	GoVersion    string `json:"goVersion"`
	NumGoroutine int    `json:"numGoroutine"`
}

func InitOS

func InitOS() (o Os)

type Ram

type Ram struct {
	UsedMB      int `json:"usedMb"`
	TotalMB     int `json:"totalMb"`
	UsedPercent int `json:"usedPercent"`
}

func InitRAM

func InitRAM() (r Ram, err error)

type Rules

type Rules map[string][]string

type RulesMap

type RulesMap map[string]Rules

type Server

type Server struct {
	Os   Os   `json:"os"`
	Cpu  Cpu  `json:"cpu"`
	Ram  Ram  `json:"ram"`
	Disk Disk `json:"disk"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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