settings

package
v0.2.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: 15 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"
	KeyRegistrationWindowH  = "registration_window_hours"
	KeyOpenRegistrationEnds = "open_registration_until"
	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
	// MaxRegistrationWindowHours is one year.
	MaxRegistrationWindowHours = 8760
)

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 DeadlineValue added in v0.2.0

func DeadlineValue(t *time.Time) any

DeadlineValue renders a sign-up deadline as the value to store for open_registration_until; nil is JSON null.

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.

func WindowEnd added in v0.2.0

func WindowEnd(now time.Time, hours int) *time.Time

WindowEnd is the sign-up deadline for a window opened at now: nil when hours is 0 (no deadline).

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) CloseRegistration added in v0.2.0

func (s *Store) CloseRegistration(ctx context.Context, actor audit.Actor) error

CloseRegistration switches sign-up off and clears the deadline.

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) PushPayload

func (s *Store) PushPayload() string

PushPayload is PushMinimal or PushFull.

func (*Store) RegistrationClosesAt added in v0.2.0

func (s *Store) RegistrationClosesAt() *time.Time

RegistrationClosesAt is the sign-up deadline; nil when sign-up is switched off or has no deadline. It does not look at the clock: a deadline that has passed is still returned, so callers check RegistrationOpen too.

func (*Store) RegistrationOpen added in v0.2.0

func (s *Store) RegistrationOpen(now time.Time) bool

RegistrationOpen reports whether anyone may self-register at now: the switch is on and the deadline, if any, has not passed. Every sign-up check goes through here.

func (*Store) ReopenRegistration added in v0.2.0

func (s *Store) ReopenRegistration(ctx context.Context, actor audit.Actor, now time.Time) error

ReopenRegistration switches sign-up on and starts a new window at now.

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) SetManyAt added in v0.2.0

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

SetManyAt is SetMany plus the sign-up deadline rules, all in one transaction. Switching open_registration on starts a new window (now plus registration_window_hours), switching it off clears the deadline, and changing registration_window_hours while sign-up is open re-bases the deadline on now. open_registration_until is not a patchable key: callers reject it before this point.

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
	RegistrationWindowH  int        // hours sign-up stays open once switched on; 0 = no deadline
	OpenRegistrationEnds *time.Time // nil = no deadline
	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.

func (Values) RegistrationOpen added in v0.2.0

func (v Values) RegistrationOpen(now time.Time) bool

RegistrationOpen is Store.RegistrationOpen on a snapshot.

Jump to

Keyboard shortcuts

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