初始化
Build docker and publish / prepare (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.admin image_name:ppanel-admin name:admin]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.api image_name:ppanel-api name:api]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.node image_name:ppanel-node name:node]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.queue image_name:ppanel-queue name:queue]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.scheduler image_name:ppanel-scheduler name:scheduler]) (push) Has been cancelled
Build docker and publish / deploy (push) Has been cancelled
Build docker and publish / notify (push) Has been cancelled
Build docker and publish / prepare (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.admin image_name:ppanel-admin name:admin]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.api image_name:ppanel-api name:api]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.node image_name:ppanel-node name:node]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.queue image_name:ppanel-queue name:queue]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.scheduler image_name:ppanel-scheduler name:scheduler]) (push) Has been cancelled
Build docker and publish / deploy (push) Has been cancelled
Build docker and publish / notify (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
KeyUserId = "user_id"
|
||||
KeyLoginType = "login_type"
|
||||
KeyIsAdmin = "is_admin"
|
||||
KeyJwtUserId = "jwtUserId"
|
||||
)
|
||||
@@ -0,0 +1,40 @@
|
||||
package jwtx
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
type Claims struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
LoginType string `json:"login_type"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
func GenerateToken(secret string, userId int64, isAdmin bool, expire int64) (string, error) {
|
||||
claims := Claims{
|
||||
UserId: userId,
|
||||
IsAdmin: isAdmin,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(expire) * time.Second)),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
},
|
||||
}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return token.SignedString([]byte(secret))
|
||||
}
|
||||
|
||||
func ParseToken(tokenStr string, secret string) (*Claims, error) {
|
||||
token, err := jwt.ParseWithClaims(tokenStr, &Claims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(secret), nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if claims, ok := token.Claims.(*Claims); ok && token.Valid {
|
||||
return claims, nil
|
||||
}
|
||||
return nil, jwt.ErrSignatureInvalid
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package result
|
||||
|
||||
import "net/http"
|
||||
|
||||
func ErrorHandler(err error) (int, any) {
|
||||
return http.StatusOK, Error(1001, err.Error())
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package result
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func Success(data interface{}) *Response {
|
||||
return &Response{Code: 0, Msg: "success", Data: data}
|
||||
}
|
||||
|
||||
func Error(code int, msg string) *Response {
|
||||
return &Response{Code: code, Msg: msg, Data: nil}
|
||||
}
|
||||
|
||||
func OkJson(w http.ResponseWriter, data interface{}) {
|
||||
httpx.OkJson(w, Success(data))
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package xerr
|
||||
|
||||
const (
|
||||
OK = 0
|
||||
ServerError = 1001
|
||||
ParamError = 1002
|
||||
TokenExpire = 1003
|
||||
TokenEmpty = 1004
|
||||
InvalidAccess = 1005
|
||||
DatabaseQueryError = 1006
|
||||
DatabaseInsertError = 1007
|
||||
DatabaseUpdateError = 1008
|
||||
DatabaseDeleteError = 1009
|
||||
UserNotFound = 2001
|
||||
UserDisabled = 2002
|
||||
PasswordError = 2003
|
||||
OrderNotFound = 3001
|
||||
OrderExpired = 3002
|
||||
PaymentFailed = 4001
|
||||
SubscribeExpired = 5001
|
||||
NodeAuthFailed = 6001
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
package xerr
|
||||
|
||||
var codeText = map[int]string{
|
||||
OK: "success",
|
||||
ServerError: "服务器错误",
|
||||
ParamError: "参数错误",
|
||||
TokenExpire: "Token已过期",
|
||||
TokenEmpty: "Token为空",
|
||||
InvalidAccess: "无效访问",
|
||||
DatabaseQueryError: "数据库查询错误",
|
||||
DatabaseInsertError: "数据库插入错误",
|
||||
DatabaseUpdateError: "数据库更新错误",
|
||||
DatabaseDeleteError: "数据库删除错误",
|
||||
UserNotFound: "用户不存在",
|
||||
UserDisabled: "用户已禁用",
|
||||
PasswordError: "密码错误",
|
||||
OrderNotFound: "订单不存在",
|
||||
OrderExpired: "订单已过期",
|
||||
PaymentFailed: "支付失败",
|
||||
SubscribeExpired: "订阅已过期",
|
||||
NodeAuthFailed: "节点认证失败",
|
||||
}
|
||||
|
||||
func MapErrMsg(code int) string {
|
||||
if msg, ok := codeText[code]; ok {
|
||||
return msg
|
||||
}
|
||||
return "未知错误"
|
||||
}
|
||||
Reference in New Issue
Block a user