优化页面、修复BUG

This commit is contained in:
李琦
2026-06-24 16:50:04 +08:00
parent 88ba9be318
commit 3f653bc336
36 changed files with 1672 additions and 2401 deletions

View File

@@ -31,14 +31,9 @@ func SuccessWithMsg(c *gin.Context, msg string, result interface{}) {
})
}
// Error 错误响应 (默认 Code 400)
// Error 错误响应HTTP 状态恒为 200通过 code 区分业务状态
func Error(c *gin.Context, code int, msg string) {
httpStatus := http.StatusBadRequest
if code == 500 {
httpStatus = http.StatusInternalServerError
}
c.JSON(httpStatus, Response{
c.JSON(http.StatusOK, Response{
Code: code,
Message: msg,
Result: nil,
@@ -47,7 +42,7 @@ func Error(c *gin.Context, code int, msg string) {
// ServerError 服务器错误 (Code 500)
func ServerError(c *gin.Context, err error) {
c.JSON(http.StatusInternalServerError, Response{
c.JSON(http.StatusOK, Response{
Code: 500,
Message: err.Error(),
Result: nil,

17
server/utils/visitor.go Normal file
View File

@@ -0,0 +1,17 @@
package utils
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
// GetOrSetVisitorID returns an anonymous visitor identifier from cookie, creating one if missing.
func GetOrSetVisitorID(c *gin.Context) string {
if cookie, err := c.Cookie("visitor_id"); err == nil && cookie != "" {
return cookie
}
id := uuid.New().String()
c.SetCookie("visitor_id", id, 365*24*3600, "/", "", false, true)
return id
}