package main import ( "log" "net/http" "strconv" "github.com/gin-gonic/gin" ) // MovieList 电影列表 func MovieList(c *gin.Context) { data := gin.H{} response := gin.H{ "code": http.StatusInternalServerError, "message": "", "data": data, } defer c.JSON(0, response) var page int = 0 spage := c.Query("page") if spage != "" { p, err := strconv.Atoi(spage) if err != nil { log.Println(err) } page = p - 1 } var limit int = 10 slimit := c.Query("limit") if slimit != "" { l, err := strconv.Atoi(slimit) if err != nil { log.Println(err) } limit = l } start := page * limit var end int = start + limit if end > len(movies) { end = len(movies) } response["code"] = http.StatusOK data["items"] = movies[start:end] data["total"] = len(movies) }