chore: fix typo

This commit is contained in:
Noah Hsu
2022-07-12 18:41:16 +08:00
parent 2bff656f00
commit a16da3b45e
7 changed files with 17 additions and 6 deletions

View File

@ -5,11 +5,16 @@ type PageReq struct {
PageSize int `json:"page_size" form:"page_size"`
}
const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1
func (p *PageReq) Validate() {
if p.PageIndex < 1 {
p.PageIndex = 1
}
if p.PageSize < 1 {
p.PageSize = 50
p.PageSize = MaxInt
}
}

View File

@ -20,6 +20,7 @@ func ListMetas(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
req.Validate()
log.Debugf("%+v", req)
metas, total, err := db.GetMetas(req.PageIndex, req.PageSize)
if err != nil {

View File

@ -17,6 +17,7 @@ func ListStorages(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
req.Validate()
log.Debugf("%+v", req)
storages, total, err := db.GetStorages(req.PageIndex, req.PageSize)
if err != nil {

View File

@ -16,6 +16,7 @@ func ListUsers(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
req.Validate()
log.Debugf("%+v", req)
users, total, err := db.GetUsers(req.PageIndex, req.PageSize)
if err != nil {