settings

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: AGPL-3.0 Imports: 4 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 holds the account-settings domain: the dashboard account's persisted UI preferences (theme and the Pipelines/Repos page filters). See openspec/changes/persist-account-settings/specs/account-settings/spec.md.

Index

Constants

View Source
const (
	KeyTheme                 = "theme"
	KeyForgeFilter           = "forgeFilter"
	KeyPipelinesHealthFilter = "pipelinesHealthFilter"
	KeyPipelinesRepoSelector = "pipelinesRepoSelector"
	KeyPipelinesSortOrder    = "pipelinesSortOrder"
	KeyTelemetryWindow       = "telemetryWindow"
)

The setting keys, as stored in the JSON blob and used as PATCH request body keys -- see Store's doc comment for why a raw map keyed by these rather than a struct with pointer fields.

View Source
const (
	DefaultTheme                 = "system"
	DefaultForgeFilter           = "all"
	DefaultPipelinesHealthFilter = "unhealthy"
	DefaultPipelinesRepoSelector = "all"
	DefaultPipelinesSortOrder    = "name"
	DefaultTelemetryWindow       = "7d"
)

The documented default for each setting, resolved server-side whenever a key has never been explicitly set for the account (account-settings/ spec.md's "Settings defaults"). PipelinesRepoSelector's default ("all") is a sentinel meaning "every tracked repo", not a real repo ID.

View Source
const MaxRepoSelectorLength = 128

MaxRepoSelectorLength bounds the one free-text setting, a repo id or "all", so a caller can't store an arbitrarily large value (the OpenAPI spec's SettingsUpdate.pipelinesRepoSelector maxLength).

Variables

View Source
var ErrInvalidKey = errors.New("unrecognized setting key")

ErrInvalidKey is returned by Update for a key outside Keys.

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

ErrInvalidValue is returned by Update for a value outside its setting's documented set (account-settings/spec.md's "Invalid value is rejected").

Keys lists every known setting key, in a stable order -- for validating a PATCH request's keys and for the "reset Pipelines filters" convenience that clears exactly the Pipelines-prefixed ones.

PipelinesFilterKeys are the three settings "reset filters" clears in one request -- account-settings/spec.md's "Reset Pipelines filters to defaults".

Functions

func AllowedValues added in v0.85.0

func AllowedValues(key string) []string

AllowedValues lists the values a closed setting accepts, in a stable order, or none for a setting with no closed set. The slice is a copy, so a caller cannot change what the package accepts.

Types

type Service

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

Service resolves stored overrides against documented defaults, and validates an update before it ever reaches Store.

func NewService

func NewService(store Store) *Service

NewService returns a Service backed by store.

func (*Service) Get

func (s *Service) Get(ctx context.Context, userID string) (Settings, error)

Get returns userID's settings, every field resolved against its documented default.

func (*Service) ResetPipelinesFilters

func (s *Service) ResetPipelinesFilters(ctx context.Context, userID string) (Settings, error)

ResetPipelinesFilters clears the three Pipelines-page filter settings back to their defaults in one request, leaving every other setting (theme, forge filter) untouched -- account-settings/spec.md's "Reset Pipelines filters to defaults".

func (*Service) Update

func (s *Service) Update(ctx context.Context, userID string, updates map[string]*string) (Settings, error)

Update validates every key/value in updates, then applies all of them in one Patch call if -- and only if -- every one is valid; an invalid key or value rejects the whole request, leaving every previously stored value unchanged (account-settings/spec.md's "Invalid value is rejected").

type Settings

type Settings struct {
	Theme                 string
	ForgeFilter           string
	PipelinesHealthFilter string
	PipelinesRepoSelector string
	PipelinesSortOrder    string
	TelemetryWindow       string
}

Settings is every setting, fully resolved: a stored override merged onto its documented default, so a field here is never ambiguous between "unset" and "empty".

func Defaults added in v0.70.0

func Defaults() Settings

Defaults returns the documented default for every setting, the values a cleared key resolves to.

type Store

type Store interface {
	// Get returns userID's stored overrides. A key absent from the result
	// has never been set (or was cleared) and should fall back to its
	// default. A user with no settings row yet returns an empty map, not
	// an error.
	Get(ctx context.Context, userID string) (map[string]string, error)
	// Patch applies updates to userID's stored overrides: a nil value
	// clears that key (reverting it to its default on the next Get), a
	// non-nil value sets it. Returns the full resulting override map.
	Patch(ctx context.Context, userID string, updates map[string]*string) (map[string]string, error)
}

Store is the port account settings are persisted through. It works in terms of the raw, possibly-partial override map (only explicitly-set keys present) rather than a resolved Settings struct, so it -- and the wire format -- have no opinion on defaults; Service owns default resolution.

Directories

Path Synopsis
Package sqlite is the SQLite-backed adapter for the settings.Store port.
Package sqlite is the SQLite-backed adapter for the settings.Store port.

Jump to

Keyboard shortcuts

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