Documentation
¶
Overview ¶
Package appconfig loads and validates runtime application configuration.
It resolves config files from norma-style search paths, expands environment variables, applies profile overlays, and validates the decoded runtime section with ValidateSettings. Use LoadResolvedSettings to inspect merged settings or LoadConfigDocument to decode an application struct directly.
Index ¶
- Constants
- func DecodeSettings(settings map[string]any, out any) error
- func ExpandEnv(input string) (string, error)
- func LoadConfigDocument(runtimeOpts RuntimeLoadOptions, opts AppLoadOptions, out any) (string, error)
- func LoadResolvedSettings(runtimeOpts RuntimeLoadOptions, opts AppLoadOptions) (map[string]any, string, error)
- func ValidateSettings(settings map[string]any) error
- type AppLoadOptions
- type RuntimeConfig
- type RuntimeLoadOptions
Examples ¶
Constants ¶
const (
// CoreConfigFileName is the fallback config file name.
CoreConfigFileName = "config.yaml"
)
Variables ¶
This section is empty.
Functions ¶
func DecodeSettings ¶
DecodeSettings decodes a settings map into a target struct using mapstructure tags.
func LoadConfigDocument ¶
func LoadConfigDocument(runtimeOpts RuntimeLoadOptions, opts AppLoadOptions, out any) (string, error)
LoadConfigDocument loads and decodes a full app config document into out.
The selected file is single-source by priority:
- default layout: <app>.yaml first, then config.yaml
- app-dir layout (UseDotConfigAppDir): .config/<app>/config.yaml (or config-dir override targets)
Profile overrides (profiles.<name>) and app env overrides are applied before decode.
func LoadResolvedSettings ¶
func LoadResolvedSettings(runtimeOpts RuntimeLoadOptions, opts AppLoadOptions) (map[string]any, string, error)
LoadResolvedSettings loads config defaults, merges the selected file, applies profile overlays and env overrides, and returns the final settings map.
func ValidateSettings ¶
ValidateSettings decodes and validates raw "runtime" settings.
Example ¶
settings := map[string]any{
"providers": map[string]any{
"openai": map[string]any{
"type": "openai",
"openai": map[string]any{
"api_key": "test-key",
"model": "gpt-5",
},
},
},
}
fmt.Println(ValidateSettings(settings) == nil)
Output: true
Types ¶
type AppLoadOptions ¶
type AppLoadOptions struct {
// AppName selects app-specific config file names and env variable prefixes.
AppName string
// EnvPrefix overrides the environment variable prefix. Empty uses AppName.
EnvPrefix string
// DefaultsYAML is merged before on-disk configuration when provided.
DefaultsYAML []byte
// UseDotConfigAppDir resolves config from app-specific .config layout:
// - <config-dir>/<app>/config.yaml, then <config-dir>/config.yaml
// - <working-dir>/.config/<app>/config.yaml
UseDotConfigAppDir bool
}
AppLoadOptions configures app config loading on top of runtime config.
type RuntimeConfig ¶
type RuntimeConfig struct {
// Providers contains named runtime provider definitions.
Providers map[string]agentconfig.Config `json:"providers,omitempty" mapstructure:"providers" validate:"required,gt=0"`
// MCPServers contains named MCP server definitions shared by providers.
MCPServers map[string]agentconfig.MCPServerConfig `json:"mcp_servers,omitempty" mapstructure:"mcp_servers" validate:"omitempty"`
}
RuntimeConfig contains runtime agent-factory settings.
Config shape:
runtime: providers: ... mcp_servers: ...
func (RuntimeConfig) Validate ¶
func (c RuntimeConfig) Validate() error
Validate validates the runtime config.
type RuntimeLoadOptions ¶
type RuntimeLoadOptions struct {
// WorkingDir anchors relative config search paths.
WorkingDir string
// ConfigDir overrides the primary config root before fallback locations.
ConfigDir string
// Profile selects profiles.<name>; empty uses the default profile.
Profile string
}
RuntimeLoadOptions configures runtime config loading.