config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MulanPSL-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found") // ErrNotFound is key not found.

Functions

func ResolveJasyptValues

func ResolveJasyptValues(m map[string]interface{}, st JasyptSettings) error

ResolveJasyptValues decrypts ENC(...) strings in-place in the merged config map.

Types

type Config

type Config interface {
	Load() error
	Scan(v interface{}) error
	Value(key string) Value
	Watch(key string, o Observer) error
	Close() error
}

Config is a config interface.

func New

func New(opts ...Option) Config

New a config with options.

type Decoder

type Decoder func(*KeyValue, map[string]interface{}) error

Decoder is config decoder.

type JasyptOption

type JasyptOption func(*JasyptSettings)

JasyptOption configures JasyptSettings for WithJasypt.

func JasyptAlgorithm

func JasyptAlgorithm(name string) JasyptOption

JasyptAlgorithm sets the jasypt-go algorithm id (default: PBEWithAES).

func JasyptAllowMissingPassword

func JasyptAllowMissingPassword() JasyptOption

JasyptAllowMissingPassword if set, leaves ENC(...) unchanged when the password env is unset (e.g. local dev only).

func JasyptPasswordEnv

func JasyptPasswordEnv(name string) JasyptOption

JasyptPasswordEnv sets the env var name for the encryptor password (default: JASYPT_ENCRYPTOR_PASSWORD).

func JasyptPrefixSuffix

func JasyptPrefixSuffix(prefix, suffix string) JasyptOption

JasyptPrefixSuffix sets the ENC wrapper (default ENC( ... ) ).

type JasyptSettings

type JasyptSettings struct {
	// PasswordEnv names the environment variable holding the master password (e.g. JASYPT_ENCRYPTOR_PASSWORD).
	PasswordEnv string
	// Algorithm is passed to jasypt-go; use jasypt constant "PBEWithAES" (JasyptPasswordAlgorithm) for PBKDF2-SHA512 + AES-256 style payloads.
	Algorithm string
	Prefix    string
	Suffix    string
	// RequirePassword: if true (default), any ENC(...) value without a set password env causes Resolve to fail.
	RequirePassword bool
}

JasyptSettings controls decryption of values wrapped as ENC(...), similar to jasypt-spring-boot: password must come from the environment at runtime, not from config files.

type KeyValue

type KeyValue struct {
	Key    string
	Value  []byte
	Format string
}

KeyValue is config key value.

type Merge

type Merge func(dst, src interface{}) error

Merge is config merge func.

type Observer

type Observer func(string, Value)

Observer is config observer.

type Option

type Option func(*options)

Option is config option.

func WithDecoder

func WithDecoder(d Decoder) Option

WithDecoder with config decoder. DefaultDecoder behavior: If KeyValue.Format is non-empty, then KeyValue.Value will be deserialized into map[string]interface{} and stored in the config cache(map[string]interface{}) if KeyValue.Format is empty,{KeyValue.Key : KeyValue.Value} will be stored in config cache(map[string]interface{})

func WithJasypt

func WithJasypt(opts ...JasyptOption) Option

WithJasypt wraps the current Resolver: after placeholder expansion, string values matching Prefix/Suffix are decrypted. Apply after other resolver-related options if you replace WithResolver, or call ResolveJasyptValues inside your own resolver.

func WithMergeFunc

func WithMergeFunc(m Merge) Option

WithMergeFunc with config merge func.

func WithResolveActualTypes

func WithResolveActualTypes(enableConvertToType bool) Option

WithResolveActualTypes with config resolver. bool input will enable conversion of config to data types

func WithResolver

func WithResolver(r Resolver) Option

WithResolver with config resolver.

func WithScanCodec

func WithScanCodec(codecName string) Option

codec before scan

func WithSource

func WithSource(s ...Source) Option

WithSource with config source.

type Reader

type Reader interface {
	Merge(...*KeyValue) error
	Value(string) (Value, bool)
	Source() ([]byte, error)
	Resolve() error
}

Reader is config reader.

type Resolver

type Resolver func(map[string]interface{}) error

Resolver resolve placeholder in config.

type Source

type Source interface {
	Load() ([]*KeyValue, error)
	Watch() (Watcher, error)
}

Source is config source.

type Value

type Value interface {
	Bool() (bool, error)
	Int() (int64, error)
	Float() (float64, error)
	String() (string, error)
	Duration() (time.Duration, error)
	Slice() ([]Value, error)
	Map() (map[string]Value, error)
	Scan(interface{}) error
	Load() interface{}
	Store(interface{})
}

Value is config value interface.

type Watcher

type Watcher interface {
	Next() ([]*KeyValue, error)
	Stop() error
}

Watcher watches a source for changes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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