| 92 | } |
| 93 | |
| 94 | func addPerPage(p string, perPage int, params map[string]interface{}) string { |
| 95 | if _, hasPerPage := params["per_page"]; hasPerPage { |
| 96 | return p |
| 97 | } |
| 98 | |
| 99 | idx := strings.IndexRune(p, '?') |
| 100 | sep := "?" |
| 101 | |
| 102 | if idx >= 0 { |
| 103 | if qp, err := url.ParseQuery(p[idx+1:]); err == nil && qp.Get("per_page") != "" { |
| 104 | return p |
| 105 | } |
| 106 | sep = "&" |
| 107 | } |
| 108 | |
| 109 | return fmt.Sprintf("%s%sper_page=%d", p, sep, perPage) |
| 110 | } |
| 111 | |
| 112 | // paginatedArrayReader wraps a Reader to omit the opening and/or the closing square bracket of a |
| 113 | // JSON array in order to apply pagination context between multiple API requests. |