Documentation ¶
Index ¶
- Constants
- func CalculateOffset(pageNumber, pageSize int) int
- func CalculatePageNumber(offset, pageSize int) int
- func CapitalizeFirstLetter(input string) string
- func GetBoolean(ctx context.Context, params url.Values, name string, defaultValue bool) (bool, error)
- func GetKeywords(_ context.Context, params url.Values, defaultValue string) (string, error)
- func GetLimit(ctx context.Context, params url.Values, defaultValue, maxValue int) (int, error)
- func GetPage(ctx context.Context, params url.Values, maxPage int) (int, error)
- type Date
- func DateFromTime(t time.Time) Date
- func GetEndDate(params url.Values) (endDate Date, validationErrs []core.ErrorItem)
- func GetStartDate(params url.Values) (startDate Date, validationErrs []core.ErrorItem)
- func MustParseDate(dateAsString string) Date
- func MustSetFieldsetErrID(id string) (d Date)
- func ParseDate(dateAsString string) (Date, error)
- func ValidateDateRange(from, to Date) (end Date, err error)
- type ReleaseType
- type Sort
- type ValidatedParams
Constants ¶
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" )
const DateFormat = "2006-01-02"
Variables ¶
This section is empty.
Functions ¶
func CalculateOffset ¶
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 ¶
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
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 ¶
GetKeywords validates and returns the "keywords" parameter
Types ¶
type Date ¶
type Date struct {
// contains filtered or unexported fields
}
func DateFromTime ¶
func GetEndDate ¶ added in v1.7.0
GetDates returns the validated date to parameters
func GetStartDate ¶ added in v1.7.0
GetStartDate returns the validated date from parameters
func MustParseDate ¶
func MustSetFieldsetErrID ¶ added in v1.9.0
func ValidateDateRange ¶ added in v1.7.0
ValidateDateRange returns an error and 'to' date if the 'from' date is after than the 'to' date
func (Date) GetFieldsetErrID ¶ added in v1.9.0
func (Date) HasDayValidationErr ¶ added in v1.9.0
func (Date) HasMonthValidationErr ¶ added in v1.9.0
func (Date) HasYearValidationErr ¶ added in v1.9.0
func (Date) MonthString ¶
func (Date) YearString ¶
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 ¶
GetSortOrder validates and returns the "sort" parameter
func (Sort) BackendString ¶
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