utils

package
v0.0.0-...-1d1ce7e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONFIG_ENV  = "CONFIG"
	CONFIG_FILE = "config.yaml"
)
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 CustomizeMap = make(map[string]Rules)

Functions

func BcryptCheck

func BcryptCheck(password, hash string) bool

func BcryptHash

func BcryptHash(password string) string

BcryptHash 对密码进行加密

func CreateDir

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

func DelFile

func DelFile(filePath string) error

func Eq

func Eq(mark string) string

func FileExist

func FileExist(filePath string) bool

func FileMove

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

func FirstLower

func FirstLower(s string) string

func FirstUpper

func FirstUpper(s string) string

func Ge

func Ge(mark string) string

func GetClaims

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

func GetUseID

func GetUseID(c *gin.Context) uint

GetUseID 根据 jwt 签证获取用户的ID

func GetUseUuid

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

GetUseUuid 根据 jwt 签证获取用户的uuid

func GetUserRoleId

func GetUserRoleId(c *gin.Context) uint

func GetWriteSyncer

func GetWriteSyncer(file string) zapcore.WriteSyncer

func Gt

func Gt(mark string) string

func Le

func Le(mark string) string

func Lt

func Lt(mark string) string

func MD5

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

func MaheHump

func MaheHump(s string) string

MaheHump 将字符串转换为驼峰命名

func Ne

func Ne(mark string) string

func NotEmpty

func NotEmpty() string

func PathExists

func PathExists(path string) (bool, error)

func Pointer

func Pointer[T any](in T) (out *T)

func RandomInt

func RandomInt(min, max int) int

func RandomString

func RandomString(n int) string

随机字符串

func RegexpMatch

func RegexpMatch(rule string) string

func RegisterRule

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

func StructToMap

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

StructToMap @author: [Shansec](https://github.com/shansec) @function: StructToMap @description: 结构体转 Map @param: v interface{} @return: map[string]interface{}

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)

InitCPU @author: [Shansec](https://github.com/shansec) @function: InitCPU @description: CPU信息 @return: 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)

InitDisk @author: [Shansec](https://github.com/shansec) @function: InitDisk @description: 硬盘信息 @return: 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) CreateToken

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

CreateToken 创建一个 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)

ParseToken 解析 token

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)

InitOS @author: [Shansec](https://github.com/shansec) @function: InitCPU @description: OS信息 @return: o Os, err error

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)

InitRAM @author: [Shansec](https://github.com/shansec) @function: InitRAM @description: RAM信息 @return: 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