confenv

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: MIT Imports: 3 Imported by: 0

README

conf-reader-env

Code Analysis Go Reference codecov GitHub tag (latest SemVer)

The conf reader for Environment Variables.

License

MIT licensed. See the bundled LICENSE file for more details.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(mapEnvKey map[string]string, prefix string) conf.Reader

New creates the Env reader

`mapEnvKey` is a map of the names of the environment variables and the configuration keys
`prefix` is a default prefix that will be added to all configuration keys
Example
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/sv-tools/conf"

	confenv "github.com/sv-tools/conf-reader-env"
)

const envName = "TEST_FOO"

func main() {
	if err := os.Setenv(envName, "42"); err != nil {
		panic(err)
	}

	c := conf.New().WithReaders(confenv.New(map[string]string{envName: "foo"}, ""))
	if err := c.Load(context.Background()); err != nil {
		panic(err)
	}

	fmt.Println(c.GetInt("foo"))

	if err := os.Unsetenv(envName); err != nil {
		panic(err)
	}
}
Output:

42

Types

This section is empty.

Jump to

Keyboard shortcuts

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