utils

package
v0.0.0-...-8be65b2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfigFilePath   = ToAbsPath("../config/config.toml")
	CertFilePath     = ToAbsPath("../config/tls.pem") // create your tls.pem
	KeyFilePath      = ToAbsPath("../config/tls.key") // create your tls.key
	StaticAssetsPath = ToAbsPath("../assets")
	LogDirPath       = ToAbsPath("../logs")
)
View Source
var Db *gorm.DB
View Source
var DbErr error
View Source
var Logger *logrus.Logger

Functions

func CheckAuthByUserId

func CheckAuthByUserId(c *gin.Context, userId string) (isAuth bool)

CheckAuthByUserId 通过userId判断当前有无权限

func CreateApp

func CreateApp() *gin.Engine

createApp

func CreateSafeFilePath

func CreateSafeFilePath(dirNames []string, fileName string) string

CreateSafeFilePath 创建安全的文件路径

func CreateToken

func CreateToken(uid string, password string) (string, error)

CreateToken 生成token

func GetConfig

func GetConfig() config

func GetCurrentUserId

func GetCurrentUserId(c *gin.Context) (uid string)

GetCurrentUserId 获取当前登陆的userId

func GetExecDirPath

func GetExecDirPath() string

GetExecDirPath 获取执行文件外文件夹绝对路径

func If

func If[T any](is bool, v1 T, v2 T) T

If 模拟三元运算符

func MergeJson

func MergeJson(args ...any) (map[string]any, error)

MergeJson 合并json

func ParseToken

func ParseToken(tokenStr string) (*claims, int)

ParseToken 解析token

func ToAbsPath

func ToAbsPath(filePath string) string

ToAbsPath 相对路径转绝对路径

func ToClaims

func ToClaims(data any) (res *claims, isOk bool)

ToClaims 转换为claims

func ToHashFileName

func ToHashFileName(fileName string) (hashFileName string)

ToHashFileName 转唯一文件名

func UUID

func UUID() string

UUID 生成唯一id

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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