loader

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 12 Imported by: 2

README

loader

Loader is a library for loading configuration from various sources.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InnerPath added in v0.2.0

func InnerPath(s string, v map[string]interface{}) interface{}

func MapPath added in v0.2.0

func MapPath(s string, v interface{}) interface{}

func SetLogToCtx added in v0.1.1

func SetLogToCtx(ctx context.Context, log Logger) context.Context

Types

type Cache

type Cache struct {
	Consul   *consul.API
	Vault    *vault.API
	File     *file.API
	Template *templatex.Template
}

type Call added in v0.2.0

type Call func(context.Context, string, map[string]interface{})

type Config

type Config struct {
	// Name for export value, default is empty.
	Name       string
	Export     string
	FilePerm   string
	FolderPerm string
	Statics    []ConfigStatic
	Dynamics   []ConfigDynamic
}

type ConfigConsul

type ConfigConsul struct {
	// Name for export, default is empty.
	Name string
	// Path is the location in consul KV.
	Path string
	// PathPrefix default is empty.
	PathPrefix string
	// Raw to load as raw, don't mix with other loaders.
	Raw bool
	// Codec YAML,JSON,TOML default is YAML.
	Codec string
	// InnerPath is get the inner path from vault response, / separated as db/settings.
	// Cannot work with Raw.
	InnerPath string
	// Map is the wrapper map, / separated as db/settings.
	Map string
	// Template to run go template after the load.
	Template bool
	// base64 to decode the content.
	Base64 bool
}

type ConfigContent

type ConfigContent struct {
	// Name for export, default is empty.
	Name string
	// Codec YAML,JSON,TOML default is YAML.
	Codec   string
	Content string
	Raw     bool
	// InnerPath is get the inner path from vault response, / separated as db/settings.
	// Cannot work with Raw.
	InnerPath string
	// Map is the wrapper map, / separated as db/settings.
	Map string
	// Template to run go template after the load.
	Template bool
	// base64 to decode the content.
	Base64 bool
}

type ConfigDynamic

type ConfigDynamic struct {
	Consul *ConfigConsul
}

type ConfigFile

type ConfigFile struct {
	// Name for export, default is empty.
	Name string
	// Path is the file location, [toml, yml, yaml, json] supported.
	Path string
	// Raw to load as raw, don't mix with other loaders.
	Raw bool
	// InnerPath is get the inner path from vault response, / separated as db/settings.
	// Cannot work with Raw.
	InnerPath string
	// Map is the wrapper map, / separated as db/settings.
	Map string
	// Template to run go template after the load.
	Template bool
	// base64 to decode the content.
	Base64 bool
}

type ConfigStatic

type ConfigStatic struct {
	Consul  *ConfigConsul
	Vault   *ConfigVault
	File    *ConfigFile
	Content *ConfigContent
}

type ConfigVault

type ConfigVault struct {
	// Name for export, default is empty.
	Name string
	Path string
	// PathPrefix default is empty, path_prefix is must!
	PathPrefix string
	// AppRoleBasePath default is auth/approle/login, not need to set.
	AppRoleBasePath string
	// InnerPath is get the inner path from vault response, / separated as db/settings.
	InnerPath string
	// Map is the wrapper map, / separated as db/settings.
	Map string
	// Template to run go template after the load.
	Template bool
	// base64 to decode the content.
	Base64 bool
}

type Configs

type Configs []Config

func (Configs) Load

func (c Configs) Load(ctx context.Context, wg *sync.WaitGroup, cache *Cache, call Call) error

Load loads all configs to export location. If loads with dynamic config, cancel context to stop loading.

type Data

type Data struct {
	Map  map[string]interface{}
	Raw  []byte
	Hold map[string]interface{}
}

func (*Data) AddHold added in v0.2.0

func (d *Data) AddHold(k string, v interface{})

func (*Data) Merge

func (d *Data) Merge(v map[string]interface{})

type Logger added in v0.1.1

type Logger interface {
	Error(msg string, keysAndValues ...interface{})
	Warn(msg string, keysAndValues ...interface{})
	Info(msg string, keysAndValues ...interface{})
	Debug(msg string, keysAndValues ...interface{})
}

Directories

Path Synopsis
consul module
file module
httpx module
vault module

Jump to

Keyboard shortcuts

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