| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | package pagination |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "net/url" |
||
| 5 | ) |
||
| 6 | |||
| 7 | // ExtractFromQueryParam extracts the lastID from the given URI, which is assumed to be a URL with query parameters. |
||
| 8 | // It specifically looks for a query parameter named 'from' and returns its value as a string. |
||
| 9 | // If the URI cannot be parsed or the query parameter is not found, it returns an empty string and the encountered |
||
| 10 | // error. |
||
| 11 | func ExtractFromQueryParam(uri string) (lastID string, err error) { |
||
| 12 | 1 | const from = "from" |
|
| 13 | |||
| 14 | 1 | return parseURIAndReturnQueryParam(uri, from) |
|
| 15 | } |
||
| 16 | |||
| 17 | func parseURIAndReturnQueryParam(uri string, param string) (val string, err error) { |
||
| 18 | 1 | u, err := url.Parse(uri) |
|
| 19 | 1 | if err != nil { |
|
| 20 | 1 | return "", err |
|
| 21 | } |
||
| 22 | |||
| 23 | 1 | v := u.Query().Get(param) |
|
| 24 | |||
| 25 | 1 | return v, nil |
|
| 26 | } |
||
| 27 |