Documentation
¶
Overview ¶
Package announce fetches Flowi's announcements: a short list of notices from the project, shown at startup and by `flowi news`.
The feed is a JSON document {"payload": base64, "signature": base64} whose signature is an Ed25519 signature of the decoded payload. Only a feed signed by a configured key is shown, whatever served it. The fetch is quiet by design: it has a short timeout, caches the last good feed, never follows redirects and, when anything goes wrong, still returns what the cache holds along with the reason.
Nothing is fetched unless a feed URL and at least one trusted key are configured; there is no built-in address.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadSignature = errors.New("announcements: the feed is not signed by a trusted key") ErrTooLarge = errors.New("announcements: the feed is too large") ErrRollback = errors.New("announcements: the feed is older than the one already held") ErrMalformed = errors.New("announcements: the feed is malformed") ErrNotConfigured = errors.New("announcements: no feed is configured") ErrNoKeys = errors.New("announcements: a feed is configured but no trusted key") ErrTurnedOff = errors.New("announcements: turned off") ErrBadKey = errors.New("announcements: not a valid trusted key") )
Errors a fetch can report.
Functions ¶
Types ¶
type Config ¶
type Config struct {
URL string
Keys []ed25519.PublicKey
CacheFile string
TTL time.Duration // how long a cached feed is used without asking again; default 6h
Timeout time.Duration // for the whole request; default 3s
Client *http.Client // nil → a client with Timeout that does not follow redirects
Now func() time.Time
}
Config configures a Feed.
func ConfigFrom ¶
ConfigFrom reads the announcements settings. on is false when the toggle is off or no feed URL is set, which is the default: nothing is fetched. A URL without a usable key is an error, not a silent skip, since showing unsigned text is exactly what the keys exist to prevent.
type Feed ¶
type Feed struct {
// contains filtered or unexported fields
}
Feed fetches and caches the announcements. It is safe for concurrent use in the sense that it holds no state beyond its cache file, which is replaced atomically.
func New ¶
New checks the configuration. The URL must be https (plain http only for loopback, for tests and local mirrors) and at least one key is required.
type Item ¶
type Item struct {
ID string `json:"id"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
URL string `json:"url,omitempty"` // https only
Level string `json:"level,omitempty"` // info | warning
Until time.Time `json:"until,omitempty"` // zero: no end
}
Item is one announcement, already cleaned for display.
type Result ¶
Result is what a fetch found. Stale means the items come from the cache because a fresh feed could not be had.