From 23a3d145177abe7174307f491c01d01082859ab0 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 22 Oct 2019 21:33:55 +0200 Subject: [PATCH] Changed page int64 to int since its all limit can handle --- Readme.md | 2 +- handler/config.go | 2 +- handler/read_all.go | 8 ++++---- web.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 0fb5bd3..4497a4b 100644 --- a/Readme.md +++ b/Readme.md @@ -147,7 +147,7 @@ handler.SetLoggingProvider(&log.Log) The `ReadAll`-method has a number of parameters: ```go -ReadAll(auth Auth, search string, page int64, perPage int64) (result interface{}, resultCount int64, numberOfPages int64, err error) +ReadAll(auth Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfPages int, err error) ``` The third parameter contains the requested page, the fourth parameter contains the number of items per page. diff --git a/handler/config.go b/handler/config.go index b0837ac..ef2185e 100644 --- a/handler/config.go +++ b/handler/config.go @@ -25,7 +25,7 @@ import ( type Config struct { AuthProvider *web.Auths LoggingProvider *logging.Logger - MaxItemsPerPage int64 + MaxItemsPerPage int } var config *Config diff --git a/handler/read_all.go b/handler/read_all.go index 8e995e9..aebc35a 100644 --- a/handler/read_all.go +++ b/handler/read_all.go @@ -41,7 +41,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { if page == "" { page = "1" } - pageNumber, err := strconv.ParseInt(page, 10, 64) + pageNumber, err := strconv.Atoi(page) if err != nil { config.LoggingProvider.Error(err.Error()) return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.") @@ -52,7 +52,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { // Items per page perPage := ctx.QueryParam("per_page") - perPageNumber, err := strconv.ParseInt(perPage, 10, 64) + perPageNumber, err := strconv.Atoi(perPage) if err != nil { config.LoggingProvider.Error(err.Error()) return echo.NewHTTPError(http.StatusBadRequest, "Bad per page amount requested.") @@ -76,8 +76,8 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { return HandleHTTPError(err, ctx) } - ctx.Response().Header().Set("x-pagination-total-pages", strconv.FormatInt(numberOfPages, 10)) - ctx.Response().Header().Set("x-pagination-result-count", strconv.FormatInt(resultCount, 10)) + ctx.Response().Header().Set("x-pagination-total-pages", strconv.FormatInt(int64(numberOfPages), 10)) + ctx.Response().Header().Set("x-pagination-result-count", strconv.FormatInt(int64(resultCount), 10)) ctx.Response().Header().Set("Access-Control-Expose-Headers", "x-pagination-total-pages, x-pagination-result-count") return ctx.JSON(http.StatusOK, result) diff --git a/web.go b/web.go index ba126fd..bf80bc0 100644 --- a/web.go +++ b/web.go @@ -31,7 +31,7 @@ type Rights interface { type CRUDable interface { Create(Auth) error ReadOne() error - ReadAll(auth Auth, search string, page int64, perPage int64) (result interface{}, resultCount int64, numberOfPages int64, err error) + ReadAll(auth Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfPages int, err error) Update() error Delete() error }