queryparams

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Limit       = "limit"
	Page        = "page"
	Offset      = "offset"
	SortName    = "sort"
	DayBefore   = "before-day"
	DayAfter    = "after-day"
	Before      = "before"
	MonthBefore = Before + "-month"
	After       = "after"
	MonthAfter  = After + "-month"
	YearBefore  = "before-year"
	YearAfter   = "after-year"
	Keywords    = "keywords"
	Query       = "query"
	DateFrom    = "fromDate"
	DateFromErr = DateFrom + "-error"
	DateTo      = "toDate"
	DateToErr   = DateTo + "-error"
	Type        = "release-type"
	Census      = "census"
	Highlight   = "highlight"
)
View Source
const DateFormat = "2006-01-02"

Variables

This section is empty.

Functions

func CalculateOffset

func CalculateOffset(pageNumber, pageSize int) int

CalculateOffset returns the offset (0 based) into a list, given a page number (1 based) and the size of a page. A pageNumber <= 0 or a pageSize <= 0 will give an offset of 0

func CalculatePageNumber

func CalculatePageNumber(offset, pageSize int) int

CalculatePageNumber returns the page number (1 based) containing the offset(th) (0 based) element in a list, given a page size of pageSize. An offset <= 0 or pageSize <= 0 will give a page number of 1, i.e. the first page

func CapitalizeFirstLetter added in v1.7.0

func CapitalizeFirstLetter(input string) string

CapitalizeFirstLetter is a helper function that transforms the first letter of a string to uppercase

func GetBoolean

func GetBoolean(ctx context.Context, params url.Values, name string, defaultValue bool) (bool, error)

GetBoolean finds a boolean parameter and returns a default value if not present It returns the default value together with an error if the value can't be parsed to a boolean

func GetKeywords

func GetKeywords(_ context.Context, params url.Values, defaultValue string) (string, error)

GetKeywords validates and returns the "keywords" parameter

func GetLimit

func GetLimit(ctx context.Context, params url.Values, defaultValue, maxValue int) (int, error)

GetLimit validates and returns the "limit" parameter

func GetPage

func GetPage(ctx context.Context, params url.Values, maxPage int) (int, error)

GetPage validates and returns the "page" parameter

Types

type Date

type Date struct {
	// contains filtered or unexported fields
}

func DateFromTime

func DateFromTime(t time.Time) Date

func GetEndDate added in v1.7.0

func GetEndDate(params url.Values) (endDate Date, validationErrs []core.ErrorItem)

GetDates returns the validated date to parameters

func GetStartDate added in v1.7.0

func GetStartDate(params url.Values) (startDate Date, validationErrs []core.ErrorItem)

GetStartDate returns the validated date from parameters

func MustParseDate

func MustParseDate(dateAsString string) Date

func ParseDate

func ParseDate(dateAsString string) (Date, error)

func ValidateDateRange added in v1.7.0

func ValidateDateRange(from, to Date) (end Date, err error)

ValidateDateRange returns an error and 'to' date if the 'from' date is after than the 'to' date

func (Date) DayString

func (d Date) DayString() string

func (Date) HasValidationErr added in v1.7.0

func (d Date) HasValidationErr() bool

func (Date) MonthString

func (d Date) MonthString() string

func (Date) String

func (d Date) String() string

func (Date) YearString

func (d Date) YearString() string

type ReleaseType

type ReleaseType int
const (
	Upcoming ReleaseType
	Published
	Cancelled
	Provisional
	Confirmed
	Postponed
)

func GetReleaseType

func GetReleaseType(ctx context.Context, params url.Values, defaultValue ReleaseType) (ReleaseType, error)

GetReleaseType validates and returns the "release-type" parameter

func (ReleaseType) Label

func (rt ReleaseType) Label() string

func (ReleaseType) Name

func (rt ReleaseType) Name() string

func (ReleaseType) String

func (rt ReleaseType) String() string

type Sort

type Sort int
const (
	RelDateAsc Sort
	RelDateDesc
	TitleAZ
	TitleZA
	Relevance
)

func GetSortOrder

func GetSortOrder(ctx context.Context, params url.Values, defaultValue string) (Sort, error)

GetSortOrder validates and returns the "sort" parameter

func (Sort) BackendString

func (s Sort) BackendString() string

func (Sort) String

func (s Sort) String() string

type ValidatedParams

type ValidatedParams struct {
	Limit       int
	Page        int
	Offset      int
	AfterDate   Date
	BeforeDate  Date
	Keywords    string
	Sort        Sort
	ReleaseType ReleaseType
	Provisional bool
	Confirmed   bool
	Postponed   bool
	Census      bool
	Highlight   bool
}

func (ValidatedParams) AsBackendQuery added in v1.1.0

func (vp ValidatedParams) AsBackendQuery() url.Values

AsBackendQuery converts to a url.Values object with parameters as expected by the api

func (ValidatedParams) AsFrontendQuery added in v1.1.0

func (vp ValidatedParams) AsFrontendQuery() url.Values

AsFrontendQuery converts to a url.Values object with parameters

Jump to

Keyboard shortcuts

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