Git Product home page Git Product logo

env's Introduction

env

Load environment variables from a <Key, Value> pair file. The purpose of this is to load your environment for testing locally, sometimes you are stuck in a situation where that is all you have to test, you are off the network and running all your services and databases locally.

Example <Key, Value> Pair File

VALUE_ONE = "One"
VALUE_TWO = "Two"
ENV_URI = "https://github.com/go-stuff/env"

Example Usage

It is important to know that you should never commit your environment files into any git repository, trust me, it will cause you lots of security headaches.

If you do not already have a .gitignore file create one. Then make sure you have the environment file you are using for testing in .gitignore.

In my example the environment file is .env this is an example contents of .gitignore, maybe you have one file, or maybe you setup a flag so you can switch between files for different environments:

.env
.env-dev
.env-qa
.env-prod

env uses the package https://github.com/uber-go/zap for logging purposes. You can pass it the path to your environment file and a *zap.logger.

This is how you would load the contents of the .env file into the environment:

env.File(".env", logger)

Example output:

github.com/go-stuff/grpc$ go run main.go
{"level":"info","ts":1569075534.3478606,"caller":"grpc/main.go:106","msg":"environment file was loaded","path":".env"}

Note: it the path does not exist it will only warn and just load environment variables, but if there is an error with the file or parsing the file it will call fatal

{"level":"warn","ts":1569075616.2841346,"caller":"grpc/main.go:39","msg":"path does not exist, using environment variables","path":""}

{"level":"fatal","ts":1569075459.8256843,"caller":"grpc/main.go:47","msg":"path is a directory not a file","path":"./","stacktrace":"..."}

env's People

Contributors

go-stuff avatar

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.