configdata

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSnapshotNotFound = errors.New("configdata: snapshot not found")
	ErrTableNotFound    = errors.New("configdata: table not found")
	ErrObjectNotFound   = errors.New("configdata: object not found")
	ErrCustomNotFound   = errors.New("configdata: custom data not found")
)

Functions

func CustomFrom

func CustomFrom[V any](snap *Snapshot, name Name) (V, bool)

func MustCustomFrom

func MustCustomFrom[V any](snap *Snapshot, name Name) V

func MustObjectFrom

func MustObjectFrom[V any](snap *Snapshot, name Name) V

func MustRegisterCustom

func MustRegisterCustom[V any](r *Registry, def CustomDef[V])

func MustRegisterObject

func MustRegisterObject[V any](r *Registry, def ObjectDef[V])

func MustRegisterTable

func MustRegisterTable[K comparable, V any](r *Registry, def TableDef[K, V])

func ObjectFrom

func ObjectFrom[V any](snap *Snapshot, name Name) (V, bool)

func RegisterCustom

func RegisterCustom[V any](r *Registry, def CustomDef[V]) error

func RegisterObject

func RegisterObject[V any](r *Registry, def ObjectDef[V]) error

func RegisterTable

func RegisterTable[K comparable, V any](r *Registry, def TableDef[K, V]) error

func SetDefaultStore

func SetDefaultStore(store *Store)

Types

type BuildContext

type BuildContext struct {
	Dir      string
	Snapshot *Snapshot
}

BuildContext exposes already-loaded config while building and validating a new snapshot. It is never shared with live handlers.

type CustomDef

type CustomDef[V any] struct {
	Name     Name
	Build    func(*BuildContext) (V, error)
	Validate func(*BuildContext, V) error
}

CustomDef builds runtime-only config from already-loaded table/object data.

type IndexDef

type IndexDef[V any] struct {
	Name      string
	Key       func(V) string
	SkipEmpty bool
}

IndexDef describes a string-keyed secondary index. Generated config getters can wrap the string key with typed helpers.

type Name

type Name string

Name is the stable identifier for a business configuration object.

type ObjectDef

type ObjectDef[V any] struct {
	Name     Name
	File     string
	Validate func(*BuildContext, V) error
}

ObjectDef describes a JSON object config.

type Registry

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

Registry stores schema definitions. It is normally populated during game bootstrap, before Store.Load or Store.Reload is called.

func DefaultRegistry

func DefaultRegistry() *Registry

func NewRegistry

func NewRegistry() *Registry

func (*Registry) RegisterCustom

func (r *Registry) RegisterCustom(def customDef) error

func (*Registry) RegisterObject

func (r *Registry) RegisterObject(def objectDef) error

func (*Registry) RegisterTable

func (r *Registry) RegisterTable(def tableDef) error

type ReloadEvent

type ReloadEvent struct {
	Reason    string
	Old       *Snapshot
	New       *Snapshot
	StartedAt time.Time
	AppliedAt time.Time
}

type ReloadHook

type ReloadHook struct {
	HookName    string
	Validate    func(context.Context, ReloadEvent) error
	BeforeApply func(context.Context, ReloadEvent) error
	AfterApply  func(context.Context, ReloadEvent) error
	Rollback    func(context.Context, ReloadEvent, error)
}

func (ReloadHook) AfterApplyReload

func (h ReloadHook) AfterApplyReload(ctx context.Context, event ReloadEvent) error

func (ReloadHook) BeforeApplyReload

func (h ReloadHook) BeforeApplyReload(ctx context.Context, event ReloadEvent) error

func (ReloadHook) Name

func (h ReloadHook) Name() string

func (ReloadHook) RollbackReload

func (h ReloadHook) RollbackReload(ctx context.Context, event ReloadEvent, cause error)

func (ReloadHook) ValidateReload

func (h ReloadHook) ValidateReload(ctx context.Context, event ReloadEvent) error

type ReloadListener

type ReloadListener interface {
	Name() string
	ValidateReload(context.Context, ReloadEvent) error
	BeforeApplyReload(context.Context, ReloadEvent) error
	AfterApplyReload(context.Context, ReloadEvent) error
	RollbackReload(context.Context, ReloadEvent, error)
}

type Snapshot

type Snapshot struct {
	Version  uint64
	LoadedAt time.Time
	Hash     string
	// contains filtered or unexported fields
}

Snapshot is an immutable, point-in-time view of all business configuration. A running handler should keep reading the same snapshot through the bound request Context even if the global Store is hot-reloaded while the handler is executing.

func ActiveSnapshot

func ActiveSnapshot() *Snapshot

func Current

func Current() *Snapshot

type Store

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

Store owns the current immutable config snapshot and supports hot reload by atomically publishing a newly built snapshot.

func DefaultStore

func DefaultStore() *Store

func NewStore

func NewStore(registry *Registry, dir string) *Store

func (*Store) AddReloadListener

func (s *Store) AddReloadListener(listener ReloadListener) func()

func (*Store) Current

func (s *Store) Current() *Snapshot

func (*Store) Dir

func (s *Store) Dir() string

func (*Store) DryRun

func (s *Store) DryRun(ctx context.Context, reason string) (*Snapshot, error)

func (*Store) Load

func (s *Store) Load(ctx context.Context) (*Snapshot, error)

func (*Store) Registry

func (s *Store) Registry() *Registry

func (*Store) Reload

func (s *Store) Reload(ctx context.Context) (*Snapshot, error)

func (*Store) ReloadWithReason

func (s *Store) ReloadWithReason(ctx context.Context, reason string) (*Snapshot, error)

func (*Store) Rollback

func (s *Store) Rollback(ctx context.Context, reason string) (*Snapshot, error)

func (*Store) SetDir

func (s *Store) SetDir(dir string)

func (*Store) SetLifecycleRegistry

func (s *Store) SetLifecycleRegistry(reg *lifecycle.Registry)

type Table

type Table[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Table is an immutable keyed business configuration table.

func MustTableFrom

func MustTableFrom[K comparable, V any](snap *Snapshot, name Name) *Table[K, V]

func TableFrom

func TableFrom[K comparable, V any](snap *Snapshot, name Name) (*Table[K, V], bool)

func (*Table[K, V]) Get

func (t *Table[K, V]) Get(key K) (V, bool)

func (*Table[K, V]) GetByIndex

func (t *Table[K, V]) GetByIndex(indexName string, value string) []V

func (*Table[K, V]) Len

func (t *Table[K, V]) Len() int

func (*Table[K, V]) MustGet

func (t *Table[K, V]) MustGet(key K) V

func (*Table[K, V]) Name

func (t *Table[K, V]) Name() Name

func (*Table[K, V]) Rows

func (t *Table[K, V]) Rows() []V

type TableDef

type TableDef[K comparable, V any] struct {
	Name     Name
	File     string
	Key      func(V) K
	Indexes  []IndexDef[V]
	Validate func(*BuildContext, V) error
}

TableDef describes a JSON-backed keyed table.

Jump to

Keyboard shortcuts

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