Documentation
¶
Overview ¶
Package config provides configuration loading and composition from files and environment artifacts.
Index ¶
- Constants
- func ConfigMustFromContainer(serviceContainer containercontract.Container) configcontract.Configuration
- func ConfigMustFromResolver(resolver containercontract.Resolver) configcontract.Configuration
- func IntWithDefault(configParameter configcontract.Parameter, defaultValue int) int
- func RoleAllowsBackgroundWork(role string) bool
- func RoleAllowsHttp(role string) bool
- type Configuration
- func (instance *Configuration) Cli() configcontract.CliConfiguration
- func (instance *Configuration) Get(name string) configcontract.Parameter
- func (instance *Configuration) Http() configcontract.HttpConfiguration
- func (instance *Configuration) Kernel() configcontract.KernelConfiguration
- func (instance *Configuration) MarkSecret(name string) bool
- func (instance *Configuration) MustGet(name string) configcontract.Parameter
- func (instance *Configuration) Names() []string
- func (instance *Configuration) Parameters() ParameterMap
- func (instance *Configuration) RegisterRuntime(name string, value any)
- func (instance *Configuration) RegisterRuntimeSecret(name string, value any)
- func (instance *Configuration) Resolve() error
- type Environment
- type EnvironmentSource
- type Parameter
- func (instance *Parameter) Bool() (bool, error)
- func (instance *Parameter) Duration() (time.Duration, error)
- func (instance *Parameter) EnvironmentKey() string
- func (instance *Parameter) EnvironmentValue() any
- func (instance *Parameter) Float() (float64, error)
- func (instance *Parameter) Int() (int, error)
- func (instance *Parameter) IsDefault() bool
- func (instance *Parameter) IsSecret() bool
- func (instance *Parameter) MustString() string
- func (instance *Parameter) String() string
- func (instance *Parameter) Value() any
- type ParameterMap
Constants ¶
const ( EnvDevelopment = "dev" EnvProduction = "prod" ModeHttp = "http" ModeCli = "cli" RoleWeb = "web" RoleWorker = "worker" RoleAll = "all" DefaultModeKey = "MELODY_DEFAULT_MODE" ProcessRoleKey = "MELODY_PROCESS_ROLE" EnvKey = "MELODY_ENV" HttpAddressKey = "MELODY_HTTP_ADDRESS" HttpMaxRequestBodyBytesKey = "MELODY_HTTP_MAX_REQUEST_BODY_BYTES" CliNameKey = "MELODY_CLI_NAME" CliDescriptionKey = "MELODY_CLI_DESCRIPTION" LogPathKey = "MELODY_LOG_PATH" LogLevelKey = "MELODY_LOG_LEVEL" DefaultLocaleKey = "MELODY_DEFAULT_LOCALE" PublicDirKey = "MELODY_PUBLIC_DIR" StaticIndexFileKey = "MELODY_STATIC_INDEX_FILE" StaticEnableCacheKey = "MELODY_STATIC_ENABLE_CACHE" StaticCacheMaxAgeKey = "MELODY_STATIC_CACHE_MAX_AGE" KernelDefaultMode = "kernel.default_mode" KernelProcessRole = "kernel.process_role" KernelEnv = "kernel.environment" KernelHttpAddress = "kernel.http_address" KernelHttpMaxRequestBodyBytes = "kernel.http.max_request_body_bytes" KernelCliName = "kernel.cli_name" KernelCliDescription = "kernel.cli_description" KernelLogPath = "kernel.log_path" KernelLogLevel = "kernel.log_level" KernelDefaultLocale = "kernel.default_locale" KernelPublicDir = "kernel.public_dir" KernelStaticIndexFile = "kernel.static.index_file" KernelStaticEnableCache = "kernel.static.enable_cache" KernelStaticCacheMaxAge = "kernel.static.cache_max_age" KernelProjectDir = "kernel.project_dir" KernelLogsDir = "kernel.logs_dir" KernelCacheDir = "kernel.cache_dir" )
const (
ServiceConfig = "service.config"
)
Variables ¶
This section is empty.
Functions ¶
func ConfigMustFromContainer ¶
func ConfigMustFromContainer(serviceContainer containercontract.Container) configcontract.Configuration
func ConfigMustFromResolver ¶
func ConfigMustFromResolver(resolver containercontract.Resolver) configcontract.Configuration
func IntWithDefault ¶
func IntWithDefault(configParameter configcontract.Parameter, defaultValue int) int
func RoleAllowsBackgroundWork ¶ added in v3.10.0
RoleAllowsBackgroundWork reports whether a process with the given role should start background services such as outbox relays and message consumers; the default RoleAll preserves the single-process behavior where one binary does everything. Melody itself gates nothing on the role — it is declared intent for application wiring and long-running runners to query.
func RoleAllowsHttp ¶ added in v3.10.0
RoleAllowsHttp reports whether a process with the given role is meant to serve web traffic; informational — the runtime mode, not the role, decides whether the http kernel starts.
Types ¶
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
func NewConfiguration ¶
func NewConfiguration( environment *Environment, projectDirectory string, ) (*Configuration, error)
func (*Configuration) Cli ¶
func (instance *Configuration) Cli() configcontract.CliConfiguration
func (*Configuration) Get ¶
func (instance *Configuration) Get(name string) configcontract.Parameter
func (*Configuration) Http ¶
func (instance *Configuration) Http() configcontract.HttpConfiguration
func (*Configuration) Kernel ¶
func (instance *Configuration) Kernel() configcontract.KernelConfiguration
func (*Configuration) MarkSecret ¶ added in v3.12.0
func (instance *Configuration) MarkSecret(name string) bool
MarkSecret marks an already registered parameter as holding a credential. The parameters melody registers automatically from the .env artifacts are the ones most likely to hold one, and they exist before any module runs, so marking them is separate from declaring them.
An absent parameter is left alone rather than reported: an environment key is legitimately undefined in some environments, and refusing to boot over one would make the marking unusable exactly where it matters. The secret column of debug:parameters is what confirms a marking took effect.
func (*Configuration) MustGet ¶
func (instance *Configuration) MustGet(name string) configcontract.Parameter
func (*Configuration) Names ¶
func (instance *Configuration) Names() []string
func (*Configuration) Parameters ¶
func (instance *Configuration) Parameters() ParameterMap
func (*Configuration) RegisterRuntime ¶
func (instance *Configuration) RegisterRuntime(name string, value any)
func (*Configuration) RegisterRuntimeSecret ¶ added in v3.12.0
func (instance *Configuration) RegisterRuntimeSecret(name string, value any)
RegisterRuntimeSecret registers a parameter that holds a credential, so that the commands which render the configuration redact it. The value is stored and resolved like any other: the marking governs display, not storage, and it travels to every parameter whose template reads this one. It does not travel backwards: the parameter melody auto-registered from the environment key this template reads holds the same credential and needs its own MarkSecret.
func (*Configuration) Resolve ¶
func (instance *Configuration) Resolve() error
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
func NewEnvironment ¶
func NewEnvironment(source configcontract.EnvironmentSource) (*Environment, error)
func (*Environment) All ¶
func (instance *Environment) All() map[string]string
type EnvironmentSource ¶
type EnvironmentSource struct {
// contains filtered or unexported fields
}
func NewEnvironmentSource ¶
func NewEnvironmentSource( fileSystem fs.FS, baseDir string, ) *EnvironmentSource
type Parameter ¶
type Parameter struct {
// contains filtered or unexported fields
}
func NewParameter ¶
func (*Parameter) EnvironmentKey ¶
func (*Parameter) EnvironmentValue ¶
func (*Parameter) IsSecret ¶ added in v3.12.0
IsSecret reports whether the parameter was declared as holding a credential, either directly or by resolving a template that reads one. Commands that render the configuration redact such a parameter; the value itself is untouched.