Files
BlackBean/internal/server/response.go
T
2026-08-14 23:41:57 +08:00

32 lines
625 B
Go

package server
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
// fail 统一错误响应:{ "error": "..." }
func fail(c *gin.Context, status int, message string) {
c.JSON(status, gin.H{"error": message})
}
// ok 统一成功响应。
func ok(c *gin.Context, data gin.H) {
c.JSON(http.StatusOK, data)
}
// parsePagination 解析 limit / offset 查询参数(非法值归零)。
func parsePagination(c *gin.Context) (limit, offset int) {
limit, _ = strconv.Atoi(c.Query("limit"))
offset, _ = strconv.Atoi(c.Query("offset"))
if limit < 0 {
limit = 0
}
if offset < 0 {
offset = 0
}
return
}