Coder Social home page Coder Social logo

thekondor / confita-prefixed-env Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 4 KB

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

License: MIT License

Go 100.00%
golang confita microservices-configuration environment-variables environment-configuration 12-factor 12factor 12factorapp

confita-prefixed-env's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.