util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeOk              = 200   // 正常
	CodeErr             = -1    // 通用异常
	CodeErrForceModify  = 60201 // 强制修改时使用
	CodeErrPlatform     = 60202 // 第三方调用异常
	CodeErrAuth         = 60400 // 登录过期,请重新登录
	CodeErrParam        = 60403 // 参数异常
	CodeErrDataNotExist = 60404 // 数据不存在
	CodeErrDB           = 60500 // 数据库异常
)
View Source
const (
	MsgOk                    = "Success"
	MsgErr                   = "系统异常"
	MsgErrAuth               = "登录过期,请重新登录"
	MsgErrParam              = "参数异常"
	MsgErrDB                 = "数据库异常"
	MsgErrNet                = "网络异常"
	MsgErrUsernameOrPassword = "用户名或密码错误"
	MsgErrOldPasswordWrong   = "旧密码错误"
	MsgErrNameExist          = "名称已存在"
	MsgErrDataNotExist       = "暂无数据"
)

Variables

View Source
var (
	// ErrNameExists 名称已存在
	ErrNameExists = errors.New("name already exists")
	// ErrListenPortExists 监听端口已存在
	ErrListenPortExists = errors.New("listen port already exists")
	// ErrProxyNotExist 代理不存在
	ErrProxyNotExist = errors.New("proxy not exists")
)
View Source
var (
	AppName                 = "my-proxy"
	AppVersion              = "1.0.0"
	DateTimeWithMilliLayout = "2006-01-02 15:04:05.000"
	JwtKey                  = "LnGvpbI59mPaSxA3"

	// ServerPortKey 服务端口 KEY
	ServerPortKey = "SERVER_PORT_KEY"
)

Functions

func FormFileReadAll

func FormFileReadAll(c *gin.Context, fileName string) ([]byte, error)

FormFileReadAll 读取表单文件内容

func GetDbPath

func GetDbPath() (string, error)

GetDbPath 获取数据库路径

func GetLogPath

func GetLogPath() string

GetLogPath 获取日志路径

func ResponseError

func ResponseError(c *gin.Context, err error)

ResponseError 错误响应

func ResponseFile

func ResponseFile(c *gin.Context, data []byte, fileName string)

ResponseFile 简单文件返回

data 文件数据 fileName 文件名,例如:xxx.json

func ResponseMsg

func ResponseMsg(c *gin.Context, code int, msg string)

ResponseMsg 未携带数据的响应

func ResponseOk

func ResponseOk(c *gin.Context)

ResponseOk 成功的响应

func ResponseOkWithData

func ResponseOkWithData(c *gin.Context, data any)

ResponseOkWithData 携带数据的成功响应

func ResponseOkWithList

func ResponseOkWithList(c *gin.Context, list any, count ...int64)

ResponseOkWithList 数据列表的成功响应

list 数据列表 count 数据总数

func ResponseWithData

func ResponseWithData(c *gin.Context, code int, msg string, data any)

ResponseWithData 发送携带数据的响应

Types

type BaseResponse

type BaseResponse struct {
	Code int    `json:"code"` // 错误码
	Msg  string `json:"msg"`  // 提示文本
	Data any    `json:"data"` // 数据
}

type UserClaim

type UserClaim struct {
	Username string `json:"username"` // 用户名
	Level    string `json:"level"`    // 用户等级, root:超级管理员
	jwt.StandardClaims
}

func AnalyzeToken

func AnalyzeToken(token string) (*UserClaim, error)

AnalyzeToken 解析token

func (*UserClaim) GenerateToken

func (uc *UserClaim) GenerateToken(expireAt int64) (string, error)

GenerateToken 生成token

expireAt: 过期时间,时间戳,秒

Jump to

Keyboard shortcuts

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