Documentation
¶
Overview ¶
Package fx keeps the dollar-to-yuan rate the CNY currency preference (see internal/settings) converts list-price costs with. It asks a free, no-key endpoint for it, keeps what it got for TTL in a small cache file beside magpie's other caches, and falls back to the last rate it ever had — or a fixed default, when it has never reached the network — while offline. Nothing here changes what usage.Record and its Totals store: they stay in USD, and only what's shown is converted.
Index ¶
Constants ¶
const Fallback = 7.2
Fallback is the rate shown when magpie has never reached rateURL and has no cache of its own: roughly what a dollar has been worth in yuan, fixed so a first run offline still shows something plausible rather than nothing.
const TTL = 12 * time.Hour
TTL is how long a fetched rate is used before another is asked for.
Variables ¶
This section is empty.
Functions ¶
func Reset ¶
func Reset()
Reset forgets the in-memory rate, so the next Get rereads the cache file or asks rateURL again; tests use it between cases.
func SetRateURL ¶ added in v0.1.652
func SetRateURL(u string) (restore func())
SetRateURL points the rate at u until the returned func puts it back; for other packages' tests.
Types ¶
type Rate ¶
Rate is a USD→CNY snapshot: how much one dollar is worth right now (CNYPerUSD) and when that was learned (At; the zero time for Fallback, which was never learned from anywhere).
func Get ¶
Get is the rate to show right now: what this process (or, failing that, the cache file) last learned, if it's under TTL old; else a fresh fetch of rateURL, kept in the cache for next time; else — offline, or the endpoint's reply didn't parse — the last rate however old, or Fallback when there has never been one.