init: first steps

This commit is contained in:
2025-07-20 23:50:47 +03:00
commit 5f26ad6941
25 changed files with 1134 additions and 0 deletions

46
pkg/http/extract.go Normal file
View File

@@ -0,0 +1,46 @@
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
}