Documentation
¶
Index ¶
- func EnsureRequired(value, key, context string) error
- func InitializeEnvEncVariablesFromFile(appEnvironment, publicKey, privateKey string) error
- func InitializeEnvEncVariablesFromResources(appEnvironment, publicKey, privateKey string, ...) error
- func RequireString(key, context string) (string, error)
- func RequireWhen(condition bool, key, context, value string) error
- type ConfigInterface
- type EnvEncConfig
- type EnvEncError
- type LoadAccumulator
- type MissingEnvError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureRequired ¶ added in v0.37.0
EnsureRequired returns a MissingEnvError when the supplied value is blank after trimming whitespace.
func InitializeEnvEncVariablesFromFile ¶ added in v0.34.0
InitializeEnvEncVariablesFromFile initializes environment variables from encrypted vault files on the filesystem based on the application environment.
Business logic:
- Requires ENV_ENCRYPTION_KEY_PUBLIC and ENV_ENCRYPTION_KEY_PRIVATE environment variables
- Looks for vault file named ".env.<app_environment>.vault" in the local filesystem
- Derives encryption key from public and private keys using envenc.DeriveKey
- Hydrates environment variables from the vault file using envenc.HydrateEnvFromFile
Parameters: - appEnvironment: The application environment (e.g., "development", "production", "staging") - publicKey: The public encryption key (typically from ENV_ENCRYPTION_KEY_PUBLIC) - privateKey: The private encryption key (typically from ENV_ENCRYPTION_KEY_PRIVATE)
Returns: - error: If any step fails (missing keys, vault file not found, decryption failed, etc.)
func InitializeEnvEncVariablesFromResources ¶ added in v0.34.0
func InitializeEnvEncVariablesFromResources(appEnvironment, publicKey, privateKey string, resourceLoader func(string) (string, error)) error
InitializeEnvEncVariablesFromResources initializes environment variables from encrypted vault files from embedded resources based on the application environment.
Business logic:
- Requires ENV_ENCRYPTION_KEY_PUBLIC and ENV_ENCRYPTION_KEY_PRIVATE environment variables
- Looks for vault resource named ".env.<app_environment>.vault" in embedded resources
- Derives encryption key from public and private keys using envenc.DeriveKey
- Hydrates environment variables from the vault content using envenc.HydrateEnvFromString
Parameters: - appEnvironment: The application environment (e.g., "development", "production", "staging") - publicKey: The public encryption key (typically from ENV_ENCRYPTION_KEY_PUBLIC) - privateKey: The private encryption key (typically from ENV_ENCRYPTION_KEY_PRIVATE) - resourceLoader: Function to load embedded resources, returns vault content
Returns: - error: If any step fails (missing keys, resource not found, decryption failed, etc.)
func RequireString ¶ added in v0.37.0
RequireString trims and retrieves the environment value for the provided key, returning a typed MissingEnvError when the value is absent.
func RequireWhen ¶ added in v0.37.0
RequireWhen validates that the given value is present when the supplied condition evaluates to true.
Types ¶
type ConfigInterface ¶
type ConfigInterface interface {
object.SerializablePropertyObjectInterface
}
ConfigInterface represents the application configuration
type EnvEncConfig ¶ added in v0.34.0
EnvEncConfig represents the environment encryption configuration
type EnvEncError ¶ added in v0.34.0
EnvEncError represents an error during environment encryption operations
func (*EnvEncError) Error ¶ added in v0.34.0
func (e *EnvEncError) Error() string
type LoadAccumulator ¶ added in v0.37.0
type LoadAccumulator struct {
// contains filtered or unexported fields
}
LoadAccumulator centralizes validation error collection while building a configuration instance. Helper methods mirror the existing RequireString and RequireWhen primitives so callers stay concise.
func (*LoadAccumulator) Add ¶ added in v0.37.0
func (a *LoadAccumulator) Add(err error)
Add appends err to the accumulator when it is non-nil.
func (*LoadAccumulator) Err ¶ added in v0.37.0
func (a *LoadAccumulator) Err() error
Err returns a ValidationError wrapping all collected issues. Nil is returned when no errors were recorded.
func (*LoadAccumulator) MustString ¶ added in v0.37.0
func (a *LoadAccumulator) MustString(key, context string) string
MustString returns the value for key via RequireString, while recording any resulting error for later inspection.
func (*LoadAccumulator) MustWhen ¶ added in v0.37.0
func (a *LoadAccumulator) MustWhen(condition bool, key, context, value string)
MustWhen delegates to RequireWhen and records any error produced under the supplied condition.
type MissingEnvError ¶ added in v0.34.0
MissingEnvError describes an unset required environment variable with optional context to aid debugging.
func (MissingEnvError) Error ¶ added in v0.34.0
func (e MissingEnvError) Error() string
Error returns the formatted error describing the missing environment variable and optional context.
type ValidationError ¶ added in v0.37.0
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError aggregates multiple missing/invalid environment errors while preserving the existing error semantics.
func (ValidationError) Error ¶ added in v0.37.0
func (e ValidationError) Error() string
func (ValidationError) Errors ¶ added in v0.37.0
func (e ValidationError) Errors() []error
Errors exposes the accumulated error slice. A defensive copy is returned to avoid callers mutating internal state.