config

package
v0.1.4-0...-0b1df8e Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package config provides Runa config primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindNamed

func BindNamed(store *Store, scope string, group string, name string, target any) (bool, error)

BindNamed binds scope.group.name into target and reports whether it exists.

func BindProvider

func BindProvider(ctx runaprovider.Context, scope string, key string, target any) error

BindProvider binds a provider-scoped config subtree into target.

func LoadFiles

func LoadFiles(store *Store, configPath string, env string, prefixes ...string) error

LoadFiles loads base config files, current-env files, then environment variables.

func Provider

func Provider(basePath string, paths Paths, dir string, env string, prefixes ...string) runaprovider.Provider

Provider registers the application config store and loads config sources.

Types

type EnvSource

type EnvSource struct {
	Prefix string
}

EnvSource loads config values from environment variables.

func Env

func Env(prefix string) EnvSource

Env creates an environment config source.

func (EnvSource) Load

func (source EnvSource) Load(string) (map[string]any, error)

Load loads environment values.

type FileSource

type FileSource struct {
	Path   string
	Domain string
}

FileSource loads a TOML file.

func File

func File(path string) FileSource

File creates a file config source.

func FileDomain

func FileDomain(path string, domain string) FileSource

FileDomain creates a file config source scoped under a domain.

func (FileSource) Load

func (source FileSource) Load(basePath string) (map[string]any, error)

Load loads file source values.

type MapSource

type MapSource struct {
	Values map[string]any
}

MapSource loads config values from a map.

func Map

func Map(values map[string]any) MapSource

Map creates a map config source.

func (MapSource) Load

func (source MapSource) Load(string) (map[string]any, error)

Load loads map source values.

type Paths

type Paths interface {
	BasePath(paths ...string) string
	AppPath(paths ...string) string
	ConfigPath(paths ...string) string
	DataPath(paths ...string) string
	PublicPath(paths ...string) string
}

Paths resolves application paths for config placeholders.

type Source

type Source interface {
	Load(basePath string) (map[string]any, error)
}

Source loads configuration values.

type Store

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

Store stores merged configuration values.

func New

func New(basePath string, paths Paths) *Store

New creates a config store.

func (*Store) Bind

func (store *Store) Bind(key string, target any) error

Bind binds a config subtree into target.

func (*Store) Default

func (store *Store) Default(key string, value any) error

Default sets a config value only when it does not exist.

func (*Store) Get

func (store *Store) Get[T any](key string, fallback ...T) T

Get reads a config key cast to T.

func (*Store) GetInt

func (store *Store) GetInt(key string, fallback int) int

GetInt reads an int config key.

func (*Store) GetString

func (store *Store) GetString(key string, fallback string) string

GetString reads a string config key.

func (*Store) Has

func (store *Store) Has(key string) bool

Has reports whether a config key exists.

func (*Store) Load

func (store *Store) Load(sources ...Source) error

Load registers and immediately loads config sources.

func (*Store) Reload

func (store *Store) Reload() error

Reload reloads all registered config sources.

func (*Store) Scope

func (store *Store) Scope(name string) *Store

Scope returns a scoped config view.

func (*Store) Set

func (store *Store) Set(key string, value any) error

Set sets a config value.

func (*Store) Values

func (store *Store) Values() map[string]any

Values returns a merged config snapshot.

Jump to

Keyboard shortcuts

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