meta

package
v0.0.0-...-ec625fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortAscending  = "asc"
	SortDescending = "desc"
)

SortXXX are default values for order_type query params.

View Source
const DefaultPerPage = 10

DefaultPerPage is a default value for per_page query params.

Variables

View Source
var ErrInvalidMetadata = errors.New("invalid metadata")

ErrInvalidMetadata is an error when metadata is invalid. This error usually returned by the implementation of Filter interface.

Functions

func PageCalculate

func PageCalculate(count int64, limit int64) int64

PageCalculate calculate total page from count

Types

type DateRange

type DateRange struct {
	Field string    `json:"field"`
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
}

func DateRangeFromURL

func DateRangeFromURL(u *fiber.Ctx, field string, startQuery, endQuery string) (*DateRange, error)

type Filter

type Filter interface {
	// Sortable returns true if a given field is allowed for sorting.
	Sortable(field string) bool
}

Filter knows how to validate filterable fields. This Filter usually implemented by Repository.

type Filtering

type Filtering struct {
	OrderBy   string `json:"order_by"`
	OrderType string `json:"order_type"`
	Search    string `json:"search,omitempty"`
	SearchBy  string `json:"search_by,omitempty"`
	Status    string `json:"status,omitempty"`
}

Filtering represents a filterable fields.

func FilterFromURL

func FilterFromURL(u *fiber.Ctx) Filtering

FilterFromURL Querys filter values from query params.

type Metadata

type Metadata struct {
	Pagination
	Filtering
	*DateRange `json:"date_range,omitempty"`
}

Metadata represents a metadata for HTTP API.

func MetadataFromURL

func MetadataFromURL(u *fiber.Ctx) Metadata

MetadataFromURL gets metadata from the given request url.

type MetadataPage

type MetadataPage struct {
	PaginationPage `json:"pagination"`
	Filtering
	*DateRange `json:"date_range,omitempty"`
}

func ConvertMetaPage

func ConvertMetaPage(m Metadata) MetadataPage

Convert Meta to MetaPage

type Pagination

type Pagination struct {
	PerPage int `json:"per_page"`
	Page    int `json:"page"`
	Total   int `json:"total"`
}

Pagination is a meta data for pagination.

func PaginationFromURL

func PaginationFromURL(u *fiber.Ctx) Pagination

PaginationFromURL Querys pagination meta from request URL.

type PaginationPage

type PaginationPage struct {
	PerPage   int `json:"per_page"`
	Page      int `json:"page"`
	TotalPage int `json:"total_page"`
}

PaginationPage is a meta data for pagination with total page.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL