func ParseSearch(u *url.URL) (brew.Search, error, []string) { args := u.Query() search := brew.Search{} funcs := []func(*brew.Search, url.Values) error{ parseMulticolor, parseRarity, parseTypes, parseSupertypes, parseColors, parseSubtypes, parseFormat, parseStatus, parseMultiverseIDs, parseSets, parseName, parseRules, parsePaging, } var err error results := []string{} for _, fun := range funcs { if e := fun(&search, args); e != nil { results = append(results, e.Error()) err = fmt.Errorf("Errors while processing the search") } } // By default, include 100 cards search.Limit = 100 return search, err, results }
func parsePaging(s *brew.Search, args url.Values) error { s.Limit = 100 pagenum := args.Get("page") if pagenum == "" { return nil } page, err := strconv.Atoi(pagenum) if err != nil { return err } if page < 0 { return fmt.Errorf("Page parameter must be >= 0") } s.Page = page s.Offset = s.Page * s.Limit return nil }