provider

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(source string) (map[string]string, error)

Load loads a configuration source and returns its content as a flattened map[string]string.

The source string format is:

[optional:]<provider>:<path>
<path> (defaults to file provider)

Examples:

  • "file:./config.yaml" // file provider, required
  • "optional:file:./config.yaml" // file provider, optional
  • "./config.yaml" // shorthand for file:./config.yaml
  • "etcd:localhost:2379/config" // custom provider
  • "optional:etcd:localhost:2379/config" // custom provider, optional

When optional is true and the source does not exist, Load returns (nil, nil).

func LoadFile

func LoadFile(optional bool, source string) (map[string]string, error)

LoadFile loads a configuration file and returns its content as a flattened map[string]string. If the file does not exist and optional is true, it returns nil without error.

func Register

func Register(name string, p Provider)

Register registers a Provider for a specific configuration source type. Must be called in init functions only.

Types

type Provider

type Provider func(optional bool, source string) (map[string]string, error)

Provider defines a function type that provides configuration data from a specific source.

If access to a remote server is needed, the information required to access it is usually placed in the source string or passed through environment variables.

To support dynamic refresh, a version number field can be added and a regular Bean can be registered to listen for changes. When the version changes, the configuration can be updated.

Jump to

Keyboard shortcuts

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