configs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package configs manages runtime-editable configuration stored in the `configs` table. Adding a new app-level knob is a two-step change:

  1. Declare a default in appDefaults() below + add its key constant.
  2. (Optional) Add a typed accessor on Service — e.g. AppURL(), SessionSecret() — so callers don't juggle strings.

Module-level configs live in each module's Config struct; the framework reflects those at boot via entity.StructToConfigs.

Values live in a cache guarded by RWMutex, populated at startup and refreshed on every Set() — so hot-reload is transparent to callers.

Index

Constants

View Source
const (
	KeyAppName              = "app_name"
	DefaultAppName          = "Wick Mini Tools"
	KeyAppDescription       = "app_description"
	DefaultAppDescription   = "A lightweight internal tooling platform — build, deploy, and run custom tools for your team in minutes."
	KeyAppURL               = "app_url"
	KeySessionSecret        = "session_secret"
	KeyAdminPasswordChanged = "admin_password_changed"
)

Canonical key constants. Always reference a variable by these rather than the string literal — renaming then becomes a one-line change the compiler catches everywhere.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

Service exposes typed, cached access to runtime variables. The cache is loaded once at startup by Bootstrap() and refreshed on every Set() / Regenerate() call, so reads never touch the DB.

func NewService

func NewService(db *gorm.DB) *Service

func (*Service) AdminPasswordChanged

func (s *Service) AdminPasswordChanged() bool

func (*Service) AppDescription

func (s *Service) AppDescription() string

func (*Service) AppName

func (s *Service) AppName() string

func (*Service) AppURL

func (s *Service) AppURL() string

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context, extras ...entity.Config) error

Bootstrap reconciles the given extras plus the app-level defaults with the DB and seeds the in-memory cache. Pass module-declared Configs collected from every registered tool/job — wick assigns Owner before handing them off. Call once at startup, before anything else reads config.

func (*Service) Get

func (s *Service) Get(key string) string

Get returns the cached value for the app-level key (Owner==""). Callers should prefer typed accessors (AppURL, SessionSecret) so renames are compiler-enforced.

func (*Service) GetOwned

func (s *Service) GetOwned(owner, key string) string

GetOwned returns the cached value for (owner, key), or empty string if missing. Tool/job handlers use this via Ctx helpers; cross-owner reads are allowed but should be rare and intentional.

func (*Service) List

func (s *Service) List() []entity.Config

List returns every app-level variable. Kept for backward compatibility with the admin settings page.

func (*Service) ListOwned

func (s *Service) ListOwned(owner string) []entity.Config

ListOwned returns every config scoped to owner in declaration order (app-level follows appDefaults(); per-owner follows map iteration).

func (*Service) Missing

func (s *Service) Missing(owner string) []string

Missing returns the keys of every Required row in owner that has no value stored. Tool handlers call this via Ctx.Missing() to render a "setup required" banner before doing any work.

func (*Service) Regenerate

func (s *Service) Regenerate(ctx context.Context, key string) error

Regenerate replaces an app-level key's value by running its registered generator. Fails if the key is unknown, has no generator, or is not flagged CanRegenerate.

func (*Service) SessionSecret

func (s *Service) SessionSecret() string

func (*Service) Set

func (s *Service) Set(ctx context.Context, key, value string) error

Set persists a new value for the app-level key and refreshes the cache. Returns an error if the key is unknown.

func (*Service) SetOwned

func (s *Service) SetOwned(ctx context.Context, owner, key, value string) error

SetOwned persists a new value for (owner, key) and refreshes the cache. Returns an error if that pair was never declared.

Jump to

Keyboard shortcuts

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