loader

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InnerPath

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

InnerPath returns the value at the / separated path inside v.

An empty path returns v unchanged. A missing path returns nil.

func MapPath

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

MapPath wraps v inside a nested map described by the / separated path s.

An empty path returns v unchanged.

Types

type Call

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

Call is invoked after a Config finishes loading (and on every dynamic reload) with the config name and the accumulated named values.

type Config

type Config struct {
	// Name for export value, default is empty.
	Name       string          `cfg:"name"`
	Export     string          `cfg:"export"`
	FilePerm   string          `cfg:"file_perm"`
	FolderPerm string          `cfg:"folder_perm"`
	Statics    []ConfigStatic  `cfg:"statics"`
	Dynamics   []ConfigDynamic `cfg:"dynamics"`
}

Config is a single load configuration.

type ConfigConsul

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

type ConfigContent

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

type ConfigDynamic

type ConfigDynamic struct {
	Consul *ConfigConsul `cfg:"consul"`
}

ConfigDynamic is a source watched/reloaded while running.

type ConfigFile

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

type ConfigHTTP added in v0.9.1

type ConfigHTTP struct {
	// Name for export, default is empty.
	Name string `cfg:"name"`
	// URL is the endpoint to fetch the configuration from.
	URL string `cfg:"url"`
	// Method is the HTTP method, default is GET.
	Method string `cfg:"method"`
	// Headers to set on the request.
	Headers map[string]string `cfg:"headers"`
	// Query parameters added to the URL.
	Query map[string]string `cfg:"query"`
	// Body is the optional request body.
	Body string `cfg:"body"`
	// Timeout for the request, default is no timeout.
	Timeout time.Duration `cfg:"timeout"`
	// Codec YAML,JSON,TOML default detects from the response Content-Type
	// and falls back to YAML.
	Codec string `cfg:"codec"`
	// InsecureSkipVerify disables TLS certificate verification.
	InsecureSkipVerify bool `cfg:"insecure_skip_verify"`
	// Raw to load as raw, don't mix with other loaders.
	Raw bool `cfg:"raw"`
	// InnerPath is get the inner path from response, / separated as db/settings.
	// Cannot work with Raw.
	InnerPath string `cfg:"inner_path"`
	// Map is the wrapper map, / separated as db/settings.
	Map string `cfg:"map"`
	// Template to run go template after the load.
	Template bool `cfg:"template"`
	// Base64 to decode the content.
	Base64 bool `cfg:"base64"`
}

type ConfigStatic

type ConfigStatic struct {
	Consul  *ConfigConsul  `cfg:"consul"`
	Vault   *ConfigVault   `cfg:"vault"`
	File    *ConfigFile    `cfg:"file"`
	Content *ConfigContent `cfg:"content"`
	HTTP    *ConfigHTTP    `cfg:"http"`
}

ConfigStatic is a source loaded once at startup.

type ConfigVault

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

type Configs

type Configs []Config

Configs is a list of load configurations.

func (Configs) Load

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

Load loads all configs to their export location and in memory.

If a config uses dynamic sources, cancel ctx to stop watching.

type Data

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

Data holds the accumulated state while loading a single Config.

  • Map is the merged map of all non-raw sources.
  • Raw is the last raw value (used when a source produces non-map content).
  • Hold keeps named values exposed to templates and the load callback.

func (*Data) AddHold

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

AddHold stores a named value in Hold. Empty keys are ignored.

func (*Data) Merge

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

Merge merges v into the running Map.

Jump to

Keyboard shortcuts

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