package main import ( "github.com/gin-gonic/gin" "net/http" "strconv" ) type Item struct { ID int `json:"id"` Name string `json:"name"` } var items = []Item{ {1, "Item 1"}, {2, "Item 2"}, {3, "Item 3"}, {4, "Item 4"}, {5, "Item 5"}, {6, "Item 6"}, {7, "Item 7"}, // Add more items as needed } func main() { router := gin.Default() router.GET("/items", func(c *gin.Context) { pageStr := c.Query("page") limitStr := c.Query("limit") page, err := strconv.Atoi(pageStr) if err != nil || page < 1 { page = 1 } limit, err := strconv.Atoi(limitStr) if err != nil || limit < 1 { limit = 2 // Default limit } start := (page - 1) * limit end := start + limit if start > len(items) { start = len(items) } if end > len(items) { end = len(items) } paginatedItems := items[start:end] c.JSON(http.StatusOK, gin.H{ "page": page, "limit": limit, "items": paginatedItems, }) }) router.Run(":8080") }
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?