prefixed_env

package module
v0.0.0-...-ba6d207 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: MIT Imports: 5 Imported by: 0

README

Confita's Prefixed Environment Backend

DEPRECATED: in favor of https://github.com/thekondor/confita-sugar, which provides a more comprehensive solution.

This code provides with a backend implementation of reading environment variables for Confita library. In contrast to the original Confita's one, this implementation allows to prefix/vendor environment variables to mitigate naming mess and make application's configuration more clear.

Example

In a setup similar to the following one:

example-config.yml:

---
server:
  host: 127.0.0.1
  port: 8080

config.go:

import (
...
    prefixed_env "github.com/thekondor/confita-prefixed-env"
...
)
...
type Config struct {
   Server struct {
       Host string `config:"server_host"`
       Port uint32 `config:"server_port"`
   }
}
...
loader := confita.NewLoader(
    ...
    prefixed_env.NewDefaultBackend("MY_APP")
    ...
)

the values of Config.Host and Config.Port could be overwritten by setting MY_APP_SERVER_HOST and MY_APP_SERVER_PORT environment variables instead of SERVER_HOST and SERVER_PORT respectively.

Usage

prefixed-env backend is created using the following functions:

  • NewDefaultBackend(prefix_name)
  • NewBackend(prefix_name, prefix_delimiter)

where prefix_name is a name of a vendored prefix to be used in a variable lookup; prefix_delimiter is a separator between prefix_name and environment's variable name (default one is underscore _).

Example of the usafe could be found in backend_test.go.

License

The library is released under the MIT license. See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPrefix = errors.New("Invalid or empty prefix")
)

Functions

func NewBackend

func NewBackend(prefix string, prefixDelimeter string) confita_backend.Backend

NewDefault() returns Confita Backend configured with a prefixDelimiter provided

func NewDefaultBackend

func NewDefaultBackend(prefix string) confita_backend.Backend

NewDefaultBackend() returns Confita Backend configured with underscore ('_') prefix delimiter

Types

This section is empty.

Jump to

Keyboard shortcuts

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