Documentation
¶
Index ¶
- Constants
- Variables
- func DetectRequestLanguage(c *gin.Context) string
- func FormFileReadAll(c *gin.Context, fileName string) ([]byte, error)
- func GetDbPath() (string, error)
- func GetLogPath() string
- func GetRequestLanguage(c *gin.Context) string
- func LocalizeMessage(c *gin.Context, message string) string
- func NormalizeLanguage(language string) string
- func ResponseError(c *gin.Context, err error)
- func ResponseFile(c *gin.Context, data []byte, fileName string)
- func ResponseMsg(c *gin.Context, code int, msg string)
- func ResponseOk(c *gin.Context)
- func ResponseOkWithData(c *gin.Context, data any)
- func ResponseOkWithList(c *gin.Context, list any, count ...int64)
- func ResponseWithData(c *gin.Context, code int, msg string, data any)
- func SetRequestLanguage(c *gin.Context, language string) string
- func TranslateMessage(language string, message string) string
- type BaseResponse
- type UserClaim
Constants ¶
View Source
const ( LanguageHeader = "language" LanguageContextKey = "language" LanguageZhCN = "zh-CN" LanguageEnUS = "en-US" DefaultLanguage = LanguageZhCN )
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.1.0" DateTimeWithMilliLayout = "2006-01-02 15:04:05.000" // JwtKey JWT 签名密钥,由 initJwtSecret 在首次运行时自动生成并持久化到数据库 JwtKey = "" // ServerPortKey 服务端口 KEY ServerPortKey = "SERVER_PORT_KEY" // ConfigKeyJwtSecret JWT 签名密钥 KEY ConfigKeyJwtSecret = "JWT_SECRET_KEY" // ConfigKeyAuditRetentionDays 日志审计存储时长(天) ConfigKeyAuditRetentionDays = "AUDIT_RETENTION_DAYS" // ConfigKeyAlertRetentionDays 告警通知存储时长(天) ConfigKeyAlertRetentionDays = "ALERT_RETENTION_DAYS" // ConfigKeyTokenExpiryDays Token 有效期(天),0 表示永不过期 ConfigKeyTokenExpiryDays = "TOKEN_EXPIRY_DAYS" DefaultAuditRetentionDays = "90" // 日志审计默认 90 天 DefaultAlertRetentionDays = "90" // 告警通知默认 90 天 DefaultServerPort = "12312" // 服务端口默认值 DefaultTokenExpiryDays = "1" // Token 有效期默认 1 天 )
Functions ¶
func DetectRequestLanguage ¶ added in v1.2.0
func FormFileReadAll ¶
FormFileReadAll 读取表单文件内容
func GetRequestLanguage ¶ added in v1.2.0
func NormalizeLanguage ¶ added in v1.2.0
func ResponseOkWithData ¶
ResponseOkWithData 携带数据的成功响应
func ResponseWithData ¶
ResponseWithData 发送携带数据的响应
func SetRequestLanguage ¶ added in v1.2.0
func TranslateMessage ¶ added in v1.2.0
Types ¶
type BaseResponse ¶
type UserClaim ¶
type UserClaim struct {
Username string `json:"username"` // 用户名
Level string `json:"level"` // 用户等级, root:超级管理员
RoleID string `json:"role_id"` // 角色UUID
jwt.StandardClaims
}
Click to show internal directories.
Click to hide internal directories.