fix: harden handler context and rate limit isolation

This commit is contained in:
Your Name
2026-05-28 20:30:24 +08:00
parent e46567678f
commit caad1aba0c
6 changed files with 311 additions and 37 deletions

View File

@@ -759,6 +759,15 @@ func getUserIDFromContext(c *gin.Context) (int64, bool) {
return id, ok
}
func getUsernameFromContext(c *gin.Context) (string, bool) {
username, exists := c.Get("username")
if !exists {
return "", false
}
usernameStr, ok := username.(string)
return usernameStr, ok
}
// handleError 将 error 转换为对应的 HTTP 响应。
// 优先识别 ApplicationError其次通过关键词推断业务错误类型兜底返回 500。
func handleError(c *gin.Context, err error) {