Documentation
¶
Overview ¶
defaults.go
format.go
keyring.go
load.go
loader.go
options.go
patch.go
public.go
reference_sources.go
references.go
schema.go
secret.go
sensitive.go
validate.go
value.go
write.go
Index ¶
- Variables
- type Loader
- func (l *Loader) ConfigPath() string
- func (l *Loader) Decode(dst any) error
- func (l *Loader) DefaultsJSON() ([]byte, error)
- func (l *Loader) DeleteKeyringValue(key string) error
- func (l *Loader) ExportPublicJSON(path string) error
- func (l *Loader) Format(state fmt.State, _ rune)
- func (l *Loader) GetKeyringValue(key string) (string, error)
- func (l *Loader) GoString() string
- func (l *Loader) Load(path string) error
- func (l *Loader) LoadJSON(name string, data []byte) error
- func (l *Loader) LoadWithParser(path string, parser koanf.Parser) error
- func (l *Loader) LogValue() slog.Value
- func (l *Loader) Map() (map[string]any, error)
- func (l *Loader) Patch(patch any) error
- func (l *Loader) PublicJSON() ([]byte, error)
- func (l *Loader) RawMap() (map[string]any, error)
- func (l *Loader) SetKeyringValue(key, value string) error
- func (l *Loader) String() string
- func (l *Loader) WriteDefaults(path string) error
- func (l *Loader) WriteDefaultsWithParser(path string, parser koanf.Parser) error
- type Option
- type PresentedSecret
- type ReferenceOptions
- type Secret
- type SecretFactory
- type SecretPresenter
- type SecretValue
- func (s SecretValue) Format(state fmt.State, _ rune)
- func (s SecretValue) GoString() string
- func (s SecretValue) IsSet() bool
- func (s SecretValue) LogValue() slog.Value
- func (s SecretValue) MarshalJSON() ([]byte, error)
- func (s SecretValue) MarshalText() ([]byte, error)
- func (s SecretValue) Path() string
- func (s SecretValue) Reveal() string
- func (s SecretValue) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrNotLoaded = errors.New("configuration has not been loaded")
ErrNotLoaded is returned when an operation requires loaded configuration.
Functions ¶
This section is empty.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader validates configuration with one embedded CUE schema.
func New ¶
New constructs a Loader from a CUE schema embedded by the application.
//go:embed config.cue var schema []byte loader, err := s99config.New(schema)
func NewFS ¶
NewFS constructs a Loader from all .cue files in dir of an embedded filesystem. The files are compiled together as one CUE package.
//go:embed schema/*.cue var schemas embed.FS loader, err := s99config.NewFS(schemas, "schema")
func (*Loader) ConfigPath ¶
ConfigPath returns the absolute path last passed to Load.
func (*Loader) Decode ¶
Decode unmarshals the resolved, default-filled configuration into dst. Loaded sensitive fields must accept the configured Secret implementation.
func (*Loader) DefaultsJSON ¶
DefaultsJSON returns an indented JSON configuration populated entirely from schema defaults. It returns an error if required fields do not have defaults. Sensitive defaults are materialized verbatim; treat the result as private.
func (*Loader) DeleteKeyringValue ¶
DeleteKeyringValue removes a value from the configured keyring service.
func (*Loader) ExportPublicJSON ¶
ExportPublicJSON writes indented configuration without sensitive values.
func (*Loader) GetKeyringValue ¶
GetKeyringValue retrieves a value from the configured keyring service.
func (*Loader) Load ¶
Load reads configuration based on its .json, .yaml, .yml, or .toml extension. CUE defaults are included in the loaded value.
func (*Loader) LoadJSON ¶
LoadJSON validates JSON from memory. name is reported in errors and provides a location for relative references.
func (*Loader) LoadWithParser ¶
LoadWithParser reads configuration using a custom Koanf parser.
func (*Loader) Map ¶
Map returns a copy of the resolved, default-filled configuration, replacing loaded sensitive values with configured Secret implementations.
func (*Loader) Patch ¶
Patch deep-merges into the file last loaded by Load and validates before writing it. Existing raw reference expressions are preserved.
func (*Loader) PublicJSON ¶
PublicJSON returns configuration without sensitive fields.
func (*Loader) RawMap ¶
RawMap returns a copy of the original configuration object before defaults and reference resolution, replacing loaded sensitive values with configured Secret implementations.
func (*Loader) SetKeyringValue ¶
SetKeyringValue stores a value in the configured keyring service.
func (*Loader) WriteDefaults ¶
WriteDefaults writes a default-filled configuration based on the path extension. The schema must provide defaults for every required value. New configuration files are created with owner-only permissions.
type Option ¶
type Option func(*options) error
Option configures a Loader.
func WithDefinition ¶
WithDefinition selects the CUE definition used for validation. The default is "#Config".
func WithReferences ¶
func WithReferences(refs ReferenceOptions) Option
WithReferences enables resolution of @{source:key} strings.
func WithSecretFactory ¶
func WithSecretFactory(factory SecretFactory) Option
WithSecretFactory selects the Secret implementation injected for sensitive loaded values. The factory receives an opaque SecretValue handle. A nil or typed-nil Secret returned by the factory falls back to the default redacted handle.
type PresentedSecret ¶
type PresentedSecret struct {
SecretValue
// contains filtered or unexported fields
}
PresentedSecret adapts a SecretValue to a custom output representation. It implements Secret for fmt, JSON, text marshaling, and log/slog consistently. Embed it in an application-defined type when distinct config field types are useful.
func NewPresentedSecret ¶
func NewPresentedSecret(value SecretValue, presenter SecretPresenter) PresentedSecret
NewPresentedSecret wraps value with a custom output representation. A nil presenter retains the default [redacted] representation.
func (PresentedSecret) Format ¶
func (s PresentedSecret) Format(state fmt.State, _ rune)
Format presents the configured representation for every fmt verb.
func (PresentedSecret) GoString ¶
func (s PresentedSecret) GoString() string
GoString presents the configured representation.
func (PresentedSecret) LogValue ¶
func (s PresentedSecret) LogValue() slog.Value
LogValue presents the configured representation through log/slog.
func (PresentedSecret) MarshalJSON ¶
func (s PresentedSecret) MarshalJSON() ([]byte, error)
MarshalJSON marshals the configured representation.
func (PresentedSecret) MarshalText ¶
func (s PresentedSecret) MarshalText() ([]byte, error)
MarshalText returns the configured representation.
func (PresentedSecret) String ¶
func (s PresentedSecret) String() string
String presents the configured representation.
type ReferenceOptions ¶
ReferenceOptions controls opt-in @{source:key} resolution. Values returned by a source are treated as literal strings, not additional references.
type Secret ¶
type Secret interface {
Reveal() string
IsSet() bool
fmt.Stringer
fmt.GoStringer
fmt.Formatter
json.Marshaler
encoding.TextMarshaler
slog.LogValuer
}
Secret is the contract for a sensitive configuration value. Implementations choose how the value is represented in output, while Reveal is the explicit operation that provides its plaintext value.
New custom implementations should normally embed PresentedSecret, which implements every formatting and logging method in this contract.
type SecretFactory ¶
type SecretFactory func(SecretValue) Secret
SecretFactory turns an opaque sensitive value into the Secret implementation injected by Decode, Map, and RawMap.
type SecretPresenter ¶
type SecretPresenter func(SecretValue) string
SecretPresenter returns the output representation of a sensitive value. Calling Reveal from a presenter intentionally exposes some or all of that value in formatted or marshaled output.
type SecretValue ¶
type SecretValue struct {
// contains filtered or unexported fields
}
SecretValue is the default Secret implementation and the value handed to a SecretFactory. It is an opaque, path-bound handle rather than plaintext and represents itself as [redacted].
func (SecretValue) Format ¶
func (s SecretValue) Format(state fmt.State, _ rune)
Format redacts SecretValue values for every fmt formatting verb.
func (SecretValue) GoString ¶
func (s SecretValue) GoString() string
GoString prevents plaintext exposure through Go-syntax formatting.
func (SecretValue) IsSet ¶
func (s SecretValue) IsSet() bool
IsSet reports whether this handle references a loaded sensitive value.
func (SecretValue) LogValue ¶
func (s SecretValue) LogValue() slog.Value
LogValue prevents plaintext exposure through log/slog.
func (SecretValue) MarshalJSON ¶
func (s SecretValue) MarshalJSON() ([]byte, error)
MarshalJSON prevents plaintext exposure through JSON logging or exporting.
func (SecretValue) MarshalText ¶
func (s SecretValue) MarshalText() ([]byte, error)
MarshalText prevents plaintext exposure through text-marshaling loggers.
func (SecretValue) Path ¶
func (s SecretValue) Path() string
Path returns the encoded configuration path of this value. It can be used by a SecretFactory to choose presentation behavior for different fields.
func (SecretValue) Reveal ¶
func (s SecretValue) Reveal() string
Reveal returns the plaintext sensitive value referenced by this handle.
func (SecretValue) String ¶
func (s SecretValue) String() string
String prevents plaintext exposure through ordinary string formatting.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
configured-secret
command
|
|
|
custom-redaction
command
|
|
|
dynamic-redaction
command
|
|
|
formats
command
|
|
|
references
command
|
|
|
tests/schema.go
|
tests/schema.go |