Documentation
¶
Overview ¶
Package conflux provides a simple API for reading configs from the environment, yaml files, and bitwarden secrets
Index ¶
- Constants
- Variables
- func DiagnosticsToTable(data map[string]string) string
- func NewBitwardenSecretReader(configMap map[string]string) *bitwardenSecretReader
- func NewEnvReader(opts ...func(*envReader)) envReader
- func NewYAMLFileReader(path string, opts ...func(*yamlFileReader)) *yamlFileReader
- func Unmarshal(r Reader, target any) (map[string]string, error)
- func WithBitwardenSecretReader() func(*ConfigMux)
- func WithCustomLazyReader(fn func(configMap map[string]string) Reader) func(*ConfigMux)
- func WithCustomReader(r Reader) func(*ConfigMux)
- func WithEnvReader(opts ...func(*envReader)) func(*ConfigMux)
- func WithEnviron(environ []string) func(*envReader)
- func WithFileSystem(fileSystem fs.FS) func(*yamlFileReader)
- func WithPath(path string) func(*yamlFileReader)
- func WithYAMLFileReader(path string, opts ...func(*yamlFileReader)) func(*ConfigMux)
- type ConfigMux
- type DiagnosticReadResult
- type ReadResult
- type Reader
- type SimpleReadResult
Constants ¶
const ( StatusMissing = "missing" StatusLoaded = "loaded" )
Variables ¶
var ErrInvalidFields = errors.New("invalid or missing fields")
Functions ¶
func DiagnosticsToTable ¶
DiagnosticsToTable takes a diagnostic map and returns it as a pretty-printed formatted table This is useful as a user-friendly report of missing and found configuration values
func NewBitwardenSecretReader ¶
NewBitwardenSecretReader creates a new Bitwarden secret reader using the provided config map to authenticate to Bitwarden.
func NewEnvReader ¶
func NewEnvReader(opts ...func(*envReader)) envReader
NewEnvReader creates a new reader which gets key-value pairs from the environment
func NewYAMLFileReader ¶
func NewYAMLFileReader(path string, opts ...func(*yamlFileReader)) *yamlFileReader
NewYAMLFileReader creates a new reader which gets key-value pairs from YML files from specified directories/files
func Unmarshal ¶
Unmarshal reads key-value pairs from the provided Reader and unmarshals them into the target struct or map.
func WithBitwardenSecretReader ¶
func WithBitwardenSecretReader() func(*ConfigMux)
WithBitwardenSecretReader adds a Bitwarden secret reader to the config mux
func WithCustomLazyReader ¶
WithCustomLazyReader lets you add your own custom reader to the mux The difference between WithCustomReader and WithCustomLazyReader is: - WithCustomReader asks for an already-initialized reader - WithCustomLazyReader asks for a function to initialize a reader This function is useful if your reader needs to be initialized after some config values have already been read. For example, the BitwardenSecretReader would need to be initialized this way because it expects a map of configs as an argument. It uses this map to try to authenticate to Bitwarden
func WithCustomReader ¶
WithCustomReader lets you add your own custom reader to the mux your custom reader just needs to implement the "Reader" interface The difference between WithCustomReader and WithCustomLazyReader is: - WithCustomReader asks for an already-initialized reader - WithCustomLazyReader asks for a function to initialize a reader This function is useful if your reader can be initialized at the same time as the mux. WithCustomLazyReader is more powerful, but WithCustomReader is simpler to use and syntactically terse
func WithEnvReader ¶
func WithEnvReader(opts ...func(*envReader)) func(*ConfigMux)
WithEnvReader adds an environment variable reader to the config mux
func WithEnviron ¶
func WithEnviron(environ []string) func(*envReader)
WithEnviron allows specifying a custom environment slice for the envReader By default, it uses os.Environ()
func WithFileSystem ¶
WithFileSystem allows specifying a custom file system for the yamlFileReader By default, it uses the OS file system, os.DirFS(".")
func WithPath ¶
func WithPath(path string) func(*yamlFileReader)
WithPath allows specifying an additional path (file or directory) to read config from
func WithYAMLFileReader ¶
WithYAMLFileReader adds a yaml file reader to the config mux
Types ¶
type ConfigMux ¶ added in v0.5.0
type ConfigMux struct {
// contains filtered or unexported fields
}
func NewConfigMux ¶
NewConfigMux creates a new config mux which can read from multiple readers
func (*ConfigMux) Read ¶ added in v0.5.0
func (r *ConfigMux) Read() (ReadResult, error)
type DiagnosticReadResult ¶
type DiagnosticReadResult struct {
// contains filtered or unexported fields
}
DiagnosticReadResult is what you should return from a Read() function if your configuration source has diagnostics to report. For example, the BitwardenSecretReader uses this as a return value. If the BitwardenSecretReader realizes that it doesn't have enough configuration values to authenticate to Bitwarden, it fills the "diagnostics" map with information about what fields were missing.
func NewDiagnosticReadResult ¶
func NewDiagnosticReadResult(configMap, diagnostics map[string]string) DiagnosticReadResult
NewDiagnosticReadResult creates a new DiagnosticReadResult
func (DiagnosticReadResult) GetConfigMap ¶
func (r DiagnosticReadResult) GetConfigMap() map[string]string
type ReadResult ¶
type ReadResult interface {
GetConfigMap() map[string]string
// contains filtered or unexported methods
}
ReadResult is the expected return value from the Read() function of a Reader You cannot define a struct outside of this package that implements this interface. You must use either NewSimpleReadResult or NewDiagnosticReadResult to initialize a value that implements ReadResult
type Reader ¶
type Reader interface {
Read() (ReadResult, error)
}
Reader is the interface that must be implemented if you want to define your own source of reading configuration data
type SimpleReadResult ¶
type SimpleReadResult struct {
// contains filtered or unexported fields
}
SimpleReadResult is what you should return from a Read() function if your configuration source doesn't have any diagnostics to report
func NewSimpleReadResult ¶
func NewSimpleReadResult(configMap map[string]string) SimpleReadResult
NewSimpleReadResult creates a new SimpleReadResult
func (SimpleReadResult) GetConfigMap ¶
func (r SimpleReadResult) GetConfigMap() map[string]string