Skip to content
This repository has been archived by the owner on Jan 6, 2019. It is now read-only.

thekondor/confita-prefixed-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Extended environment backend for heetch's Confita library to allow vendored/prefixed system's environment variables

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages