31 lines
392 B
Go
31 lines
392 B
Go
package query
|
|
|
|
const (
|
|
DefaultLimit = 100
|
|
MaxLimit = 10000
|
|
)
|
|
|
|
type Filter struct {
|
|
StartDate string
|
|
EndDate string
|
|
Limit int
|
|
Page int
|
|
}
|
|
|
|
func NormalizeLimit(limit int) int {
|
|
if limit <= 0 {
|
|
return DefaultLimit
|
|
}
|
|
if limit > MaxLimit {
|
|
return MaxLimit
|
|
}
|
|
return limit
|
|
}
|
|
|
|
func Offset(page, limit int) int {
|
|
if page <= 1 {
|
|
return 0
|
|
}
|
|
return (page - 1) * limit
|
|
}
|