diff options
Diffstat (limited to 'errhandlers/errhandlers.go')
-rw-r--r-- | errhandlers/errhandlers.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/errhandlers/errhandlers.go b/errhandlers/errhandlers.go index 14c1d33..5f4db25 100644 --- a/errhandlers/errhandlers.go +++ b/errhandlers/errhandlers.go @@ -22,8 +22,9 @@ import ( "github.com/MikunoNaka/MAL2Go/util" ) -// if fields aren't specified +// this is only for anime fields func FieldsErrHandler(fields []string) ([]string, error) { + // if fields aren't specified if cap(fields) == 0 { // uses all the default fields if none specified return util.DefaultFields, nil @@ -40,6 +41,25 @@ func FieldsErrHandler(fields []string) ([]string, error) { return fields, nil } +// only for manga fields +func MangaFieldsErrHandler(fields []string) ([]string, error) { + // if fields aren't specified + if cap(fields) == 0 { + // uses all the default fields if none specified + return util.DefaultMangaFields, nil + } + + // checks if each given field is valid + for _, j := range(fields) { + if !IsValidMangaField(j) { + return []string{}, errors.New(fmt.Sprintf("InvalidFieldError: Invalid field specified: \"%s\"", j)) + } + } + + // everything's fine! + return fields, nil +} + // if limit or error specified are above the limit func LimitErrHandler(limit, maxLimit int) error { if limit > maxLimit { |