47 lines
897 B
Go
47 lines
897 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
func ExtractLimitOffset(r *http.Request) (int, int, ResponseErrReadyToSend) {
|
|
limit, offset := r.URL.Query().Get("limit"), r.URL.Query().Get("offset")
|
|
|
|
if limit == "" {
|
|
limit = "20"
|
|
}
|
|
|
|
if offset == "" {
|
|
offset = "0"
|
|
}
|
|
|
|
limitInt, err := strconv.Atoi(limit)
|
|
if err != nil {
|
|
writeErr := NewResponseErrBuilder().
|
|
WithMessage("Incorrect limit parameter").
|
|
WithDetails(map[string]interface{}{
|
|
"err": err.Error(),
|
|
}).
|
|
WithStatusCode(http.StatusBadRequest).
|
|
Ready()
|
|
|
|
return 0, 0, writeErr
|
|
}
|
|
|
|
offsetInt, err := strconv.Atoi(offset)
|
|
if err != nil {
|
|
writeErr := NewResponseErrBuilder().
|
|
WithMessage("Incorrect offset parameter").
|
|
WithDetails(map[string]interface{}{
|
|
"err": err.Error(),
|
|
}).
|
|
WithStatusCode(http.StatusBadRequest).
|
|
Ready()
|
|
|
|
return 0, 0, writeErr
|
|
}
|
|
|
|
return limitInt, offsetInt, nil
|
|
}
|