Documentation
¶
Index ¶
- func HandleRequest[T any](c *fiber.Ctx, query *gorm.DB, defaults Defaults, message string) error
- func OrderClause(sortBy, sortOrder string, fieldToColumn map[string]string, ...) string
- func Query[T any](ctx context.Context, query *gorm.DB, params *Params, message string) (*httpx.PaginatedResponse, error)
- type Defaults
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleRequest ¶
HandleRequest is a convenience function that handles the full pagination flow It parses, validates, applies defaults, executes query, and returns response
func OrderClause ¶ added in v1.19.0
func OrderClause(sortBy, sortOrder string, fieldToColumn map[string]string, defaultColumn string) string
OrderClause returns an ORDER BY clause (column + direction) from sort params and an allowlist. sortBy is the requested field (e.g. "name"); sortOrder is "asc" or "desc". fieldToColumn maps allowed API field names to DB column names (e.g. "name" -> "roles.name"). defaultColumn is used when sortBy is not in the map.
Types ¶
type Params ¶
type Params struct {
Page int `query:"page" validate:"min=1"`
PerPage int `query:"per_page" validate:"min=1,max=100"` // Items per page
SortBy string `query:"sort_by"` // Sort field name
SortOrder string `query:"sort_order" validate:"omitempty,oneof=asc desc"` // Sort order: asc or desc
}
Params represents pagination query parameters
Click to show internal directories.
Click to hide internal directories.