You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
528 B
32 lines
528 B
package args |
|
|
|
import ( |
|
"strconv" |
|
|
|
"github.com/gin-gonic/gin" |
|
) |
|
|
|
type PageArg struct { |
|
Page int |
|
Size int |
|
SortBy string |
|
Asc bool |
|
} |
|
|
|
func ParsePageArgs(c *gin.Context) (arg PageArg) { |
|
page := c.Param("page") |
|
size := c.Param("size") |
|
sortBy := c.Param("sortBy") |
|
asc, _ := strconv.Atoi(c.Param("asc")) |
|
arg.Page, _ = strconv.Atoi(page) |
|
arg.Size, _ = strconv.Atoi(size) |
|
arg.SortBy = sortBy |
|
arg.Asc = asc == 1 |
|
if arg.Page <= 0 { |
|
arg.Page = 1 |
|
} |
|
if arg.Size <= 0 || arg.Size > 1000 { |
|
arg.Size = 20 |
|
} |
|
return |
|
}
|
|
|