Documentation
¶
Index ¶
- func Merge(base map[string]any, conditionals ...func(m map[string]any))
- func NewCollection[T Resource](items []T) []map[string]any
- func NewPaginatedCollection[T Resource](items []T, meta PaginationMeta) map[string]any
- func When(condition bool, key string, value any) (string, any, bool)
- func WhenFunc(condition bool, key string, fn func() any) (string, any, bool)
- func WhenNotNil(key string, value any) (string, any, bool)
- type PaginationMeta
- type Paginator
- type Resource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Merge ¶
Merge adds conditional fields to a base map. Each conditional function receives the map and may add keys to it.
func NewCollection ¶
NewCollection transforms a slice of Resource-implementing items into a slice of maps suitable for JSON serialization.
func NewPaginatedCollection ¶
func NewPaginatedCollection[T Resource](items []T, meta PaginationMeta) map[string]any
NewPaginatedCollection transforms a slice of Resource-implementing items into a paginated response with data and meta fields. LastPage is auto-computed from Total and PerPage (ceiling division).
func When ¶
When returns a key-value pair that should be included in the resource only when the condition is true. The third return value indicates inclusion.
Types ¶
type PaginationMeta ¶
type PaginationMeta struct {
Total int `json:"total"`
PerPage int `json:"per_page"`
CurrentPage int `json:"current_page"`
LastPage int `json:"last_page"`
}
PaginationMeta holds pagination metadata for paginated collections.
func FromPaginator ¶
func FromPaginator(p Paginator) PaginationMeta
FromPaginator builds a PaginationMeta from any Paginator implementation. LastPage is auto-computed via ceiling division.