Documentation
¶
Overview ¶
Package fetch is the fetch plugin of MyGo: pages make HTTP requests from Go with the fetch of its JavaScript package, @caelyreth/evil-mygo-fetch, which takes and returns the standard Request options and Response. Requests made this way are not subject to CORS, may set any header (Origin, Cookie, User-Agent, ...) and read every response header but Set-Cookie and Set-Cookie2, which are filtered before sending the response to pages.
mygo.Use(fetch.Plugin)
and in the frontend:
import { fetch } from "@caelyreth/evil-mygo-fetch";
const res = await fetch("https://api.example.com/items", {
headers: { authorization: `Bearer ${token}` },
});
const items = await res.json();
The response body streams to the page as Go reads it, and aborting the request's signal cancels it in Go. URLs that are not http or https, such as the app's own pages, go to the webview's fetch.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Plugin = New(Options{})
Plugin is the plugin with the default options.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Client makes the requests; nil means a client of
// netproxy.Transport(), which follows the system's proxy settings. Its
// CheckRedirect limits the redirects followed when the request's
// redirect mode is "follow".
Client *http.Client
// Allow, when not nil, decides whether pages may make a request; a
// request it refuses rejects with an error.
Allow func(r *http.Request) bool
}
Options configure the plugin.