This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultListLimit = 25
|
||||
maximumListLimit = 100
|
||||
)
|
||||
|
||||
func parseListLimit(raw string) (int, error) {
|
||||
if raw == "" {
|
||||
return defaultListLimit, nil
|
||||
}
|
||||
limit, err := strconv.Atoi(raw)
|
||||
if err != nil || limit < 1 || limit > maximumListLimit {
|
||||
return 0, fmt.Errorf("limit must be between 1 and %d", maximumListLimit)
|
||||
}
|
||||
return limit, nil
|
||||
}
|
||||
Reference in New Issue
Block a user