This commit is contained in:
oneao committed 2025-11-11 16:35:32 +08:00
1 parent 098a061308
commit 994321d049
40 files changed
+1401 -359

No files matched your search

@@ -126,6 +126,32 @@ func (c *Context) Get(key string) (interface{}, bool) {
return val, ok
}
// SetUserID 存储 userId
func (c *Context) SetUserID(userID int64) {
c.Set("user_id", userID)
}
// GetUserID 获取 userId
func (c *Context) GetUserID() int64 {
val, ok := c.Get("user_id")
if !ok || val == nil {
return 0
}
switch v := val.(type) {
case int64:
return v
case int:
return int64(v)
case uint64:
return int64(v)
case uint:
return int64(v)
default:
return 0
}
}
// JSON 返回 JSON 响应,支持返回 error
func (c *Context) JSON(statusCode int, data interface{}) error {
c.RequestCtx.SetStatusCode(statusCode)