This commit is contained in:
oneao committed 2025-08-13 22:00:31 +08:00
1 parent 01ea998605
commit d1b1aafc57
9 files changed
+82 -35

No files matched your search

@@ -3,6 +3,7 @@ package jwt
import (
commonConfig "base-framework/pkg/config"
"errors"
"fmt"
"time"
"github.com/golang-jwt/jwt"
@@ -23,6 +24,7 @@ type CustomClaims struct {
// CreateToken 创建一个 JWT token
func CreateToken(orgID, userID string) (string, error) {
expireAt := time.Now().Add(commonConfig.JWT.Expiry)
fmt.Println("Token 过期时间:", expireAt.Format(time.RFC3339))
claims := CustomClaims{
OrgID: orgID,
@@ -5,19 +5,25 @@ import (
"net/http"
)
// 统一响应结构体
type ErrorInfo struct {
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
Message string `json:"message,omitempty"`
Stack string `json:"stack,omitempty"`
}
// Result 统一响应结构体
type Result struct {
Code string `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
Error *ErrorInfo `json:"error,omitempty"`
}
const (
// 通用
CodeSuccess = "0000" // 成功
CodeFail = "0001" // 失败
// 鉴权 / 登录
CodeNoLogin = "1001" // 未登录
CodeLoginExpired = "1002" // 登录过期
CodeInvalidToken = "1003" // Token 无效
@@ -85,6 +91,12 @@ func (b *Builder) Data(data interface{}) *Builder {
return b
}
// ErrorInfo 设置错误信息
func (b *Builder) ErrorInfo(err *ErrorInfo) *Builder {
b.result.Error = err
return b
}
// Send 发送响应
func (b *Builder) Send() {
if b.result.Data == nil {