mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Refactor entry validation
This commit is contained in:
parent
806b9545a9
commit
11e110bc7d
14 changed files with 192 additions and 202 deletions
|
@ -6,6 +6,7 @@ package validator // import "miniflux.app/validator"
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"miniflux.app/locale"
|
||||
|
@ -29,6 +30,29 @@ func (v *ValidationError) Error() error {
|
|||
return errors.New(v.String())
|
||||
}
|
||||
|
||||
// ValidateRange makes sure the offset/limit values are valid.
|
||||
func ValidateRange(offset, limit int) error {
|
||||
if offset < 0 {
|
||||
return fmt.Errorf(`Offset value should be >= 0`)
|
||||
}
|
||||
|
||||
if limit < 0 {
|
||||
return fmt.Errorf(`Limit value should be >= 0`)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateDirection makes sure the sorting direction is valid.
|
||||
func ValidateDirection(direction string) error {
|
||||
switch direction {
|
||||
case "asc", "desc":
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf(`Invalid direction, valid direction values are: "asc" or "desc"`)
|
||||
}
|
||||
|
||||
func isValidURL(absoluteURL string) bool {
|
||||
_, err := url.ParseRequestURI(absoluteURL)
|
||||
return err == nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue