37 lines
743 B
Go
37 lines
743 B
Go
package libhttp
|
|
|
|
import (
|
|
"go.opentelemetry.io/otel/trace"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
func PaginationFromRequest(r *http.Request, defaultCount int) (int, int) {
|
|
_, t := tracer.Start(r.Context(), "PaginationFromRequest", trace.WithSpanKind(trace.SpanKindInternal))
|
|
defer t.End()
|
|
|
|
// get display count
|
|
count := defaultCount
|
|
if qCount, ok := r.URL.Query()["count"]; ok {
|
|
if len(qCount[0]) >= 1 {
|
|
uCount, err := strconv.ParseUint(qCount[0], 10, 64)
|
|
if err == nil {
|
|
count = int(uCount)
|
|
}
|
|
}
|
|
}
|
|
|
|
// get display page
|
|
page := 1
|
|
if qPage, ok := r.URL.Query()["page"]; ok {
|
|
if len(qPage[0]) >= 1 {
|
|
uPage, err := strconv.ParseUint(qPage[0], 10, 64)
|
|
if err == nil {
|
|
page = int(uPage)
|
|
}
|
|
}
|
|
}
|
|
|
|
return page, count
|
|
}
|