Get is a helper function that calls [Context.GetURL] with the given URL, parsed relative to the page URL of the given context. It also checks the status code of the response and closes the response body and returns an error if it is not [http.StatusOK]. If the error is nil, then the response body is
(ctx *Context, url string)
| 331 | // it is not [http.StatusOK]. If the error is nil, then the response body is |
| 332 | // not closed and must be closed by the caller. |
| 333 | func Get(ctx *Context, url string) (*http.Response, error) { |
| 334 | u, err := parseRelativeURL(url, ctx.PageURL) |
| 335 | if err != nil { |
| 336 | return nil, err |
| 337 | } |
| 338 | resp, err := ctx.GetURL(u.String()) |
| 339 | if err != nil { |
| 340 | return nil, err |
| 341 | } |
| 342 | if resp.StatusCode != http.StatusOK { |
| 343 | resp.Body.Close() |
| 344 | return resp, fmt.Errorf("got error status %q (code %d)", resp.Status, resp.StatusCode) |
| 345 | } |
| 346 | return resp, nil |
| 347 | } |
no test coverage detected