utils

package
v0.0.0-...-38e5134 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package utils @program: arco-design-pro-gin @author: [lliuhuan](https://github.com/lliuhuan) @create: 2021-12-10 13:40

Package utils @program: arco-design-pro-gin @author: [lliuhuan](https://github.com/lliuhuan) @create: 2021-12-10 13:37

Index

Constants

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

Variables

This section is empty.

Functions

func BaseValidator

func BaseValidator(obj interface{}, c *gin.Context) (string, error)

func BaseValidatorQuery

func BaseValidatorQuery(obj interface{}, c *gin.Context) (string, error)

func BaseValidatorUri

func BaseValidatorUri(obj interface{}, c *gin.Context) (string, error)

func GetClaims

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

GetClaims 根据token获取claims信息

func GetUserAuthorityId

func GetUserAuthorityId(c *gin.Context) string

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 GetWriteSyncer

func GetWriteSyncer(file string) zapcore.WriteSyncer

GetWriteSyncer zap logger中加入file-rotatelogs @author: [lliuhuan](https://github.com/lliuhuan) @function: GetWriteSyncer @description: zap logger中加入file-rotatelogs @return: zapcore.WriteSyncer, error

func MD5V

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

MD5V 简单md5加密 @author: [lliuhuan](https://github.com/lliuhuan) @function: MD5V @description: md5加密 @param: str []byte @return: string

func PathExists

func PathExists(path string) (bool, error)

PathExists 文件目录是否存在 @author: [lliuhuan](https://github.com/lliuhuan) @function: PathExists @description: 文件目录是否存在 @param: path string @return: bool, error

func Reload

func Reload() error

func StructToMap

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

StructToMap 利用反射将结构体转化为map @author: [lliuhuan](https://github.com/lliuhuan) @function: StructToMap @description: 利用反射将结构体转化为map @param: obj interface{} @return: map[string]interface{}

Types

type Cpu

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

func InitCPU

func InitCPU() (c Cpu, err error)

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

CreateClaims 创建token数据

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 OS信息 @author: [lliuhuan](https://github.com/lliuhuan) @function: InitOS @description: OS信息 @return: o Os, err error

type Process

type Process struct {
	CpuPercent     float64 `json:"cpuPercent"`
	OneCpuPercent  float64 `json:"oneCpuPercent"`
	ThreadCount    int     `json:"threadCount"`
	GoroutineCount int     `json:"goroutineCount"`
	Memory         float32 `json:"memory"`
}

func InitProcess

func InitProcess() (p Process, err error)

type Rrm

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

func InitRAM

func InitRAM() (r Rrm, err error)

InitRAM ARM信息 @author: [lliuhuan](https://github.com/lliuhuan) @function: InitRAM @description: ARM信息 @return: r Rrm, err error

type Server

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

Directories

Path Synopsis
Package captcha @program: arco-design-pro-gin @author: [lliuhuan](https://github.com/lliuhuan) @create: 2021-12-10 13:53
Package captcha @program: arco-design-pro-gin @author: [lliuhuan](https://github.com/lliuhuan) @create: 2021-12-10 13:53

Jump to

Keyboard shortcuts

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