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
- Variables
- func Keys() []string
- func Validate(key string, value any) error
- type Store
- func (s *Store) AlertRenotifyS() int
- func (s *Store) AllowedCIDRs() []netip.Prefix
- func (s *Store) DefaultRetentionDays() *int
- func (s *Store) DiskReserveBytes() int64
- func (s *Store) InstanceName() string
- func (s *Store) Invalidate()
- func (s *Store) MDNSEnabled() bool
- func (s *Store) OpenRegistration() bool
- func (s *Store) PushPayload() string
- func (s *Store) SessionIdleDays() int
- func (s *Store) Set(ctx context.Context, actor audit.Actor, key string, value any) error
- func (s *Store) SetMany(ctx context.Context, actor audit.Actor, values map[string]json.RawMessage) error
- func (s *Store) SetTx(tx *store.Tx, actor audit.Actor, key string, value any) error
- func (s *Store) UploadMaxBytes() int64
- func (s *Store) UserQuotaBytes() int64
- func (s *Store) Values() Values
- func (s *Store) WebPushEnabled() bool
- func (s *Store) WebResetEnabled() bool
- type Values
Constants ¶
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.
const ( PushMinimal = "minimal" PushFull = "full" )
Push payload modes.
const ( MaxUploadBytes = 2 << 30 MaxInstanceNameLen = 64 MaxSessionIdleDays = 90 MaxRetentionDays = 3650 )
Limits enforced by Set.
Variables ¶
var ErrInvalid = errors.New("invalid setting")
ErrInvalid is wrapped by every error that rejects a key or value.
Functions ¶
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store gives typed, cached access to the settings table.
func (*Store) AlertRenotifyS ¶
AlertRenotifyS is the default alert renotify interval in seconds.
func (*Store) AllowedCIDRs ¶
AllowedCIDRs returns the extra source ranges admitted besides private addresses. The slice is shared: do not modify it.
func (*Store) DefaultRetentionDays ¶
DefaultRetentionDays is the default channel retention; nil keeps forever.
func (*Store) DiskReserveBytes ¶
DiskReserveBytes is the free space uploads must leave.
func (*Store) InstanceName ¶
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 ¶
MDNSEnabled reports whether mDNS advertising is on.
func (*Store) OpenRegistration ¶
OpenRegistration reports whether anyone may self-register.
func (*Store) PushPayload ¶
PushPayload is PushMinimal or PushFull.
func (*Store) SessionIdleDays ¶
SessionIdleDays is the idle expiry of sessions in days.
func (*Store) Set ¶
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 ¶
SetTx is Set inside the caller's transaction (first-run setup uses it). The cache is dropped after the transaction commits.
func (*Store) UploadMaxBytes ¶
UploadMaxBytes is the per-file upload limit.
func (*Store) UserQuotaBytes ¶
UserQuotaBytes is the per-user storage quota; 0 means unlimited.
func (*Store) 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 ¶
WebPushEnabled reports whether Web Push is switched on.
func (*Store) WebResetEnabled ¶
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.