尝试登录逻辑

This commit is contained in:
des
2026-01-19 00:07:20 +08:00
parent c61fb947e7
commit 2d65afdf33
16 changed files with 713 additions and 66 deletions

View File

@@ -0,0 +1,26 @@
package common
import (
"github.com/gin-gonic/gin"
)
type ctxKey struct {
desc string
}
var (
dataKey = ctxKey{"响应体内容"}
)
// SetData 设置响应数据,可以设置为 nil或者干脆不设置。此时会返回空的响应包装。
func SetData(c *gin.Context, data any) {
c.Set(dataKey, data)
}
// GetData 获取响应数据
// 除了响应包装器,你不应该在任何地方调用该方法。因为响应数据的类型不一。
// 如果你真的对响应数据处理。请在中间件向上下文中塞入数据,在 handler 中处理好。
func GetData(c *gin.Context) any {
data, _ := c.Get(dataKey)
return data
}