loader

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package loader provides an easy way to load and merge configuration files and decode them into one single configuration struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigLoader

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

func NewConfigLoader

func NewConfigLoader(opts ...OptFunc) *ConfigLoader

NewConfigLoader creates a new ConfigLoader instances with viper and `env` function pre-loaded.

func (*ConfigLoader) AppendConfig

func (cl *ConfigLoader) AppendConfig(config, configType string) error

AppendConfig appends a plain string config (similar to a config file but in string), parses and merges it with current config.

func (*ConfigLoader) LoadConfigFiles

func (cl *ConfigLoader) LoadConfigFiles(fileNames ...string) error

LoadConfigFiles loads and parses one or more config files. The latter files will merge with previous ones in order. Should be followed by Unmarshal to create a struct out of the config.

func (*ConfigLoader) Unmarshal

func (cl *ConfigLoader) Unmarshal(v interface{}, opts ...viper.DecoderConfigOption) error

Unmarshal unmarshals current config into a struct.

func (*ConfigLoader) Viper

func (cl *ConfigLoader) Viper() *viper.Viper

Viper returns the underlying viper instance.

type OptFunc

type OptFunc func(*ConfigLoader)

func WithCustomTemplateFunc

func WithCustomTemplateFunc(name string, fn interface{}) OptFunc

WithCustomTemplateFunc registers a custom function to use with the template, similar to `env` and `vault`.

func WithDelimiters

func WithDelimiters(left, right string) OptFunc

WithDelimiters changes the default template delimiters {{ }}.

func WithVaultClient

func WithVaultClient(vaultClient *api.Client) OptFunc

WithVaultClient enables vault function to fetch secrets from Hashicorp Vault. Example: {{ vault "secrets/path" "bar_key" "default_value" }}.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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