feat: ✨ añadido función de parámetros de paginación y datos de sesión
This commit is contained in:
parent
f902581a4a
commit
be1dc3ceff
23
pages.go
23
pages.go
@ -1,5 +1,10 @@
|
||||
package gorender
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Pages contiene la información de paginación.
|
||||
type Pages struct {
|
||||
// totalElements son la cantidad de elementos totales a paginar. Pueden ser
|
||||
@ -128,3 +133,21 @@ func PaginateArray[T any](items []T, currentPage, itemsPerPage int) []T {
|
||||
|
||||
return items[startIndex:endIndex]
|
||||
}
|
||||
|
||||
func PaginationParams(r *http.Request) (int, int, int) {
|
||||
limit := r.FormValue("limit")
|
||||
if limit == "" {
|
||||
limit = "50"
|
||||
}
|
||||
page := r.FormValue("page")
|
||||
if page == "" || page == "0" {
|
||||
page = "1"
|
||||
}
|
||||
|
||||
limitInt, _ := strconv.Atoi(limit)
|
||||
pageInt, _ := strconv.Atoi(page)
|
||||
offset := (pageInt - 1) * limitInt
|
||||
actualPage := offset/limitInt + 1
|
||||
|
||||
return limitInt, offset, actualPage
|
||||
}
|
||||
|
||||
@ -32,6 +32,8 @@ type OptionFunc func(*Render)
|
||||
|
||||
type TemplateData struct {
|
||||
Data map[string]interface{}
|
||||
// SessionData contiene los datos de la sesión del usuario.
|
||||
SessionData interface{}
|
||||
// FeedbackData tiene como función mostrar los mensajes habituales de
|
||||
// información, advertencia, éxito y error. No va implícitamente relacionado
|
||||
// con los errores de validación de formularios pero pueden ser usados para
|
||||
|
||||
Loading…
Reference in New Issue
Block a user