优化页面、修复BUG
This commit is contained in:
@@ -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
17
server/utils/visitor.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user