config

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	ServiceConfig = "service.config"
)

Variables

This section is empty.

Functions

func ConfigMustFromContainer

func ConfigMustFromContainer(serviceContainer containercontract.Container) configcontract.Configuration

func ConfigMustFromResolver added in v1.1.0

func ConfigMustFromResolver(resolver containercontract.Resolver) configcontract.Configuration

func IntWithDefault added in v1.4.0

func IntWithDefault(configParameter configcontract.Parameter, defaultValue int) int

func RoleAllowsBackgroundWork added in v1.16.0

func RoleAllowsBackgroundWork(role string) bool

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 v1.16.0

func RoleAllowsHttp(role string) bool

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 (*Configuration) Get

func (instance *Configuration) Get(name string) configcontract.Parameter

func (*Configuration) Http

func (*Configuration) Kernel

func (*Configuration) MarkSecret added in v1.18.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 v1.18.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

func (*Environment) Get

func (instance *Environment) Get(key string) (string, bool)

type EnvironmentSource

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

func NewEnvironmentSource

func NewEnvironmentSource(
	fileSystem fs.FS,
	baseDir string,
) *EnvironmentSource

func (*EnvironmentSource) Load

func (instance *EnvironmentSource) Load() (map[string]string, error)

type Parameter

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

func NewParameter

func NewParameter(environmentKey string, environmentValue any, value any, isDefault bool) *Parameter

func (*Parameter) Bool

func (instance *Parameter) Bool() (bool, error)

func (*Parameter) Duration added in v1.18.0

func (instance *Parameter) Duration() (time.Duration, error)

func (*Parameter) EnvironmentKey

func (instance *Parameter) EnvironmentKey() string

func (*Parameter) EnvironmentValue

func (instance *Parameter) EnvironmentValue() any

func (*Parameter) Float added in v1.18.0

func (instance *Parameter) Float() (float64, error)

func (*Parameter) Int

func (instance *Parameter) Int() (int, error)

func (*Parameter) IsDefault

func (instance *Parameter) IsDefault() bool

func (*Parameter) IsSecret added in v1.18.0

func (instance *Parameter) IsSecret() bool

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.

func (*Parameter) MustString

func (instance *Parameter) MustString() string

func (*Parameter) String

func (instance *Parameter) String() string

func (*Parameter) Value

func (instance *Parameter) Value() any

type ParameterMap

type ParameterMap map[string]*Parameter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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