provider

package
v0.0.0-...-68bc43f Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package provider defines a built-in configuration providers that are automatically registered by usrv.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnvVars

type EnvVars struct{}

EnvVars implements a configuration provider that fetches configuration values from the environment variables associated with the currently running process.

func NewEnvVars

func NewEnvVars() *EnvVars

NewEnvVars creates a new EnvVars provider instance.

func (*EnvVars) Get

func (p *EnvVars) Get(path string) map[string]string

Get returns a map containing configuration values associated with a particular path.

To match the standard envvar form, the path is first normalized by converting it to uppercase and then replacing any path separators with an underscore while also trimming any leading separators.

The provider then scans the process envvars and selects the ones whose names begin with the normalized path. The configuration map keys are built by stripping the path prefix from any matched envvars, lowercasing the remaining part of the envvar name and replacing any underscores with the path separator.

For example, given the path "/redis/MASTER" the following envvars would be matched as configuration options:

  • REDIS_MASTER_SERVICE_HOST=10.0.0.11
  • REDIS_MASTER_PORT_6379_TCP=tcp://10.0.0.11:6379

The above options would yield the following configuration map:

{
 "service/host": "10.0.0.11",
 "port/6379/tcp": "tcp://10.0.0.11:6379",
}

func (*EnvVars) Watch

func (p *EnvVars) Watch(path string, valueSetter func(string, map[string]string)) func()

Watch installs a monitor for a particular path and invokes the supplied value changer when its value changes. The method returns a function that should be used to terminate the watch.

The

Jump to

Keyboard shortcuts

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