first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user