Documentation
¶
Overview ¶
Package source chooses where magpie reads from, with a mirror as a fallback when the official address can't be reached. The official source stays first; a mirror is only asked when it fails. The Plugins page's 「国内镜像」 switch (China) puts a mirror in China first for the few addresses one serves byte for byte.
Index ¶
- Constants
- Variables
- func ChinaFirst(raw string) string
- func Do(c *http.Client, req *http.Request) (*http.Response, error)
- func DoFaithful(c *http.Client, req *http.Request) (*http.Response, error)
- func DoOfficial(c *http.Client, req *http.Request) (*http.Response, error)
- func Enabled() bool
- func URLs(raw string) []string
Constants ¶
const NPMMirror = npmMirror
NPMMirror is npm's registry in China, npmmirror.
Variables ¶
var China = func() bool { return settings.Load().ChinaMirror }
China is whether the Plugins page's 「国内镜像」 switch is on (settings.ChinaMirror); a var for tests.
Functions ¶
func ChinaFirst ¶ added in v0.1.1829
ChinaFirst is the mirror in China the 「国内镜像」 switch asks before raw, "" with the switch off or when no mirror serves raw.
func Do ¶
Do sends req as usual and, when the official answer fails in a way a mirror could answer, tries its mirrors in order. A request that carries credentials is never sent to a mirror with them: GitHub's, whose only one is the user's token, goes to a mirror without it (bare).
func DoFaithful ¶ added in v0.1.721
DoFaithful sends req to its official address, after its mirror in China when the 「国内镜像」 switch is on, but never to a fallback mirror: for a file nothing checks, which only a copy of the very file may stand in for.
func DoOfficial ¶
DoOfficial sends req to its official address alone. It is for a file whose checksum must come from the same trusted place as the file itself.
func Enabled ¶
func Enabled() bool
Enabled reports whether mirror fallback was turned on with MAGPIE_MIRRORS=on (or true, 1, cn).
func URLs ¶
URLs is the official address followed by its mirrors, or just the official one when there is no mirror for it; with the 「国内镜像」 switch on, a mirror in China comes before it. A masking model's file has hf-mirror after it with no switch at all (modelMirror); every other fallback mirror waits for MAGPIE_MIRRORS.
Types ¶
This section is empty.