You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
722 B
40 lines
722 B
3 years ago
|
package params
|
||
3 years ago
|
|
||
3 years ago
|
// Params are generics query argument
|
||
|
type Params struct {
|
||
|
Limit int
|
||
|
Page int
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
// Modifier function takes params and makes some changes
|
||
|
type Modifier func(params Params) Params
|
||
3 years ago
|
|
||
3 years ago
|
// Modifiers is a list of modifier
|
||
|
type Modifiers []Modifier
|
||
3 years ago
|
|
||
3 years ago
|
// Apply function modifies params
|
||
|
func (ms Modifiers) Apply(params Params) Params {
|
||
3 years ago
|
|
||
3 years ago
|
for _, m := range ms {
|
||
|
params = m(params)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
return params
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
// WithLimit modifier setups the limit
|
||
|
func WithLimit(limit int) Modifier {
|
||
|
return func(params Params) Params {
|
||
|
params.Limit = limit
|
||
|
return params
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
// WithPage modifier setups the page
|
||
|
func WithPage(page int) Modifier {
|
||
|
return func(params Params) Params {
|
||
|
params.Page = page
|
||
|
return params
|
||
|
}
|
||
3 years ago
|
}
|