settings

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 14 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 settings reads and writes the instance settings stored in the settings table. Every key has a typed accessor with a default, values are cached in memory until the next Set, and Set validates the value, audits the change and appends a settings.updated event in one transaction.

Index

Constants

View Source
const (
	KeyInstanceName         = "instance_name"
	KeyOpenRegistration     = "open_registration"
	KeyUploadMaxBytes       = "upload_max_bytes"
	KeyUserQuotaBytes       = "user_quota_bytes"
	KeyDiskReserveBytes     = "disk_reserve_bytes"
	KeyDefaultRetentionDays = "default_retention_days"
	KeyWebPushEnabled       = "web_push_enabled"
	KeyPushPayload          = "push_payload"
	KeyAllowedCIDRs         = "allowed_cidrs"
	KeySessionIdleDays      = "session_idle_days"
	KeyAlertRenotifyS       = "alert_renotify_s"
	KeyMDNSEnabled          = "mdns_enabled"
	KeyWebResetEnabled      = "web_reset_enabled"
)

Setting keys.

View Source
const (
	PushMinimal = "minimal"
	PushFull    = "full"
)

Push payload modes.

View Source
const (
	MaxUploadBytes     = 2 << 30
	MaxInstanceNameLen = 64
	MaxSessionIdleDays = 90
	MaxRetentionDays   = 3650
)

Limits enforced by Set.

Variables

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

ErrInvalid is wrapped by every error that rejects a key or value.

Functions

func Keys

func Keys() []string

Keys returns every setting key.

func Validate

func Validate(key string, value any) error

Validate reports whether value is acceptable for key. The error wraps ErrInvalid.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store gives typed, cached access to the settings table.

func New

func New(db *store.DB) *Store

New returns a Store over db.

func (*Store) AlertRenotifyS

func (s *Store) AlertRenotifyS() int

AlertRenotifyS is the default alert renotify interval in seconds.

func (*Store) AllowedCIDRs

func (s *Store) AllowedCIDRs() []netip.Prefix

AllowedCIDRs returns the extra source ranges admitted besides private addresses. The slice is shared: do not modify it.

func (*Store) DefaultRetentionDays

func (s *Store) DefaultRetentionDays() *int

DefaultRetentionDays is the default channel retention; nil keeps forever.

func (*Store) DiskReserveBytes

func (s *Store) DiskReserveBytes() int64

DiskReserveBytes is the free space uploads must leave.

func (*Store) InstanceName

func (s *Store) InstanceName() string

InstanceName is the display name of this server.

func (*Store) Invalidate

func (s *Store) Invalidate()

Invalidate drops the cache; the next accessor reloads from the database. Set calls it after commit; call it after changing the table another way.

func (*Store) MDNSEnabled

func (s *Store) MDNSEnabled() bool

MDNSEnabled reports whether mDNS advertising is on.

func (*Store) OpenRegistration

func (s *Store) OpenRegistration() bool

OpenRegistration reports whether anyone may self-register.

func (*Store) PushPayload

func (s *Store) PushPayload() string

PushPayload is PushMinimal or PushFull.

func (*Store) SessionIdleDays

func (s *Store) SessionIdleDays() int

SessionIdleDays is the idle expiry of sessions in days.

func (*Store) Set

func (s *Store) Set(ctx context.Context, actor audit.Actor, key string, value any) error

Set validates value for key and stores it, audits the change and appends a settings.updated event, all in one transaction.

func (*Store) SetMany

func (s *Store) SetMany(ctx context.Context, actor audit.Actor, values map[string]json.RawMessage) error

SetMany validates every entry first and then stores all of them in one transaction, so a rejected value changes nothing. Each key is audited.

func (*Store) SetTx

func (s *Store) SetTx(tx *store.Tx, actor audit.Actor, key string, value any) error

SetTx is Set inside the caller's transaction (first-run setup uses it). The cache is dropped after the transaction commits.

func (*Store) UploadMaxBytes

func (s *Store) UploadMaxBytes() int64

UploadMaxBytes is the per-file upload limit.

func (*Store) UserQuotaBytes

func (s *Store) UserQuotaBytes() int64

UserQuotaBytes is the per-user storage quota; 0 means unlimited.

func (*Store) Values

func (s *Store) Values() Values

Values returns every setting. Rows that fail validation (edited by hand) fall back to the default; if the table cannot be read the defaults are returned and nothing is cached.

func (*Store) WebPushEnabled

func (s *Store) WebPushEnabled() bool

WebPushEnabled reports whether Web Push is switched on.

func (*Store) WebResetEnabled

func (s *Store) WebResetEnabled() bool

WebResetEnabled reports whether the admin UI may reset the instance.

type Values

type Values struct {
	InstanceName         string
	OpenRegistration     bool
	UploadMaxBytes       int64
	UserQuotaBytes       int64 // 0 = unlimited
	DiskReserveBytes     int64
	DefaultRetentionDays *int // nil = keep forever
	WebPushEnabled       bool
	PushPayload          string
	AllowedCIDRs         []netip.Prefix
	SessionIdleDays      int
	AlertRenotifyS       int
	MDNSEnabled          bool
	WebResetEnabled      bool
}

Values is a snapshot of every setting with defaults applied.

func Defaults

func Defaults() Values

Defaults returns the value of every setting on a fresh instance.

Jump to

Keyboard shortcuts

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