settings

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 6 Imported by: 0

README

togo

togo-framework/settings

marketplace pkg.go.dev MIT

Part of the togo framework.

Install

togo install togo-framework/settings

settings — shared config store for togo

A togo plugin that gives every other plugin a shared, typed config store. Values are JSON, addressed by (scope, key) — use global, a plugin name, or a tenant id — and persisted in the kernel database.

togo install togo-framework/settings

Go API

s := settings.FromKernel(k)               // *settings.Store from the kernel
_ = s.Set(ctx, settings.ScopeGlobal, "site.title", "ToGO")
title, ok, _ := settings.Get[string](ctx, s, settings.ScopeGlobal, "site.title")
all, _ := s.All(ctx, "billing")           // every key in a scope
_ = s.Delete(ctx, "billing", "plan")

REST API

Method Path Body
GET /api/settings/{scope} — → {key: value}
GET /api/settings/{scope}/{key} — → value
PUT /api/settings/{scope}/{key} any JSON
DELETE /api/settings/{scope}/{key}

Data model

settings(scope text, skey text, value text json, PRIMARY KEY (scope, skey)) — created on boot. Cross-driver TEXT columns; upsert via ON CONFLICT.

MIT


Premium sponsors

ID8 Media  ·  One Studio

Support togo — become a sponsor.

Documentation

Overview

Package settings is a togo plugin: a shared, typed config store that any other plugin can read, write, and share. Values are JSON, addressed by (scope, key) — use scope "global", a plugin name, or a tenant id — and persisted in the kernel DB. Use the Go helpers (Get/Set) or the REST API at /api/settings.

Index

Constants

View Source
const ScopeGlobal = "global"

ScopeGlobal is the default scope for app-wide settings.

Variables

This section is empty.

Functions

func Get

func Get[T any](ctx context.Context, s *Store, scope, key string) (T, bool, error)

Get is a typed convenience over Store.Get.

func Set

func Set[T any](ctx context.Context, s *Store, scope, key string, v T) error

Set is a typed convenience over Store.Set.

Types

type Store

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

Store is the settings service placed in the kernel container under "settings".

func FromKernel

func FromKernel(k *togo.Kernel) *Store

FromKernel returns the settings store, or nil if the plugin isn't installed.

func (*Store) All

func (s *Store) All(ctx context.Context, scope string) (map[string]json.RawMessage, error)

All returns every setting in a scope as raw JSON values.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, scope, key string) error

Delete removes a setting.

func (*Store) Get

func (s *Store) Get(ctx context.Context, scope, key string, dst any) (ok bool, err error)

Get unmarshals the value at (scope, key) into dst; ok=false if absent.

func (*Store) Set

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

Set stores any JSON-serialisable value under (scope, key).

Jump to

Keyboard shortcuts

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