Paginated 辅助函数:发送分页响应
(w http.ResponseWriter, items any, total, page, pageSize int)
| 67 | |
| 68 | // Paginated 辅助函数:发送分页响应 |
| 69 | func Paginated(w http.ResponseWriter, items any, total, page, pageSize int) { |
| 70 | totalPages := (total + pageSize - 1) / pageSize |
| 71 | JSON(w, http.StatusOK, &PaginatedResponse{ |
| 72 | Items: items, |
| 73 | Total: total, |
| 74 | Page: page, |
| 75 | PageSize: pageSize, |
| 76 | TotalPages: totalPages, |
| 77 | }) |
| 78 | } |
| 79 | |
| 80 | // Created 辅助函数:发送 201 Created 响应 |
| 81 | func Created(w http.ResponseWriter, data any) { |