instance

package
v0.2.2-dev.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const MaxLogoBytes = 64 << 10

MaxLogoBytes is the largest SVG the admin may upload (before sanitising).

Variables

View Source
var ErrInvalid = errors.New("invalid instance setting")

ErrInvalid wraps every validation failure, so callers can map it to INVALID_ARGUMENT.

View Source
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

func SanitizeSVG(in string) (string, error)

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 Defaults

func Defaults() Settings

Defaults returns the settings of a fresh installation.

func FromValues added in v0.1.26

func FromValues(values map[string]string) Settings

FromValues applies the stored values to the installation defaults. Missing keys keep their defaults.

func Load

func Load(ctx context.Context, st *store.Store) (Settings, error)

Load reads the settings, falling back to the default for every unset key.

func Update

func Update(ctx context.Context, st *store.Store, p Patch) (Settings, error)

Update validates the patch, applies it on top of the stored settings, saves the result and returns it. A rejected patch changes nothing.

func (Settings) BrandName

func (s Settings) BrandName() string

BrandName is the wordmark as one string ("Mistgate"), for page titles and the authenticator app's issuer label.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL