MCPcopy Create free account
hub / github.com/cogentcore/core / Get

Function Get

htmlcore/handler.go:333–347  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
333func 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}

Callers 1

handleElementFunction · 0.70

Calls 4

parseRelativeURLFunction · 0.85
StringMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected