Documentation
¶
Overview ¶
Package instance holds the settings of this panel installation that are visible to its users: the brand (a two-part wordmark and an optional logo), the accent colour and the default language. They live in the setting table; the admin API and the sign-in page read them through here. Values are validated on the way in, so what is stored can be rendered as is.
Index ¶
Constants ¶
const ( DefaultBrandHead = "Mist" DefaultBrandTail = "gate" DefaultAccent = "#7dd3a0" DefaultLanguage = "en" )
Defaults of a fresh installation: brand "Mistgate" (wordmark "mist" + "gate"), no custom logo, mint accent, English.
const MaxLogoBytes = 64 << 10
MaxLogoBytes is the largest SVG the admin may upload (before sanitising).
Variables ¶
var ErrInvalid = errors.New("invalid instance setting")
ErrInvalid wraps every validation failure, so callers can map it to INVALID_ARGUMENT.
var Languages = []string{"en", "ru", "zh", "fa", "tr"}
Languages are the supported UI languages, of the admin (web/src/i18n) and the user page (web/src/sub/i18n.ts) alike.
Functions ¶
func SanitizeSVG ¶
SanitizeSVG rewrites an SVG so it can be served and inlined safely: it keeps the allow-listed shapes, gradients and text with allow-listed attributes and drops the rest — scripts, foreign objects, event handlers, links, animation and every reference that is not "#id" inside the document. The result is rebuilt from tokens, so nothing the parser tolerated but a browser might interpret differently survives. Input over MaxLogoBytes, DOCTYPE/entity tricks, several roots and a root that is not <svg> are rejected.
func SettingKeys ¶ added in v0.1.26
func SettingKeys() []string
SettingKeys lists the keys that make up Settings.
Types ¶
type Patch ¶
type Patch struct {
BrandHead, BrandTail, Accent, Language, LogoSVG *string
}
Patch is a partial update: a nil field is left unchanged. LogoSVG "" removes the logo.
type Settings ¶
type Settings struct {
BrandHead string // first part of the wordmark, shown in the text colour
BrandTail string // second part, shown in the accent colour; may be empty
Accent string // "#rrggbb", lower case
Language string // default UI language, one of Languages
LogoSVG string // sanitised SVG, "" = none (the UI shows its built-in mark)
}
Settings are the stored, already validated values.
func FromValues ¶ added in v0.1.26
FromValues applies the stored values to the installation defaults. Missing keys keep their defaults.