Git Product home page Git Product logo

dotenv-v's Introduction

Dotenv V

Dotenv V is a package to parse environment files. It support reading in multiple environment files which are added to the process' environment variables upon load.

To use this package, import the module and call load:

import dotenv
import os

// Loads `.env` file by default
parsed := dotenv.load() or { panic(err) }
assert os.getenv('KEY') == parsed['KEY']

To load one or more specific files:

import dotenv
parsed := dotenv.load('./env_file', '/path/to/env') or { panic(err) }

Syntax

The syntax for the env files should follow the Docker spec (https://docs.docker.com/compose/environment-variables/env-file/). At the time of writing, this boils down to:

  • Lines starting with # are ignored
  • Blank lines are ignored
  • Each line is a key-value pair (no multi line). Values can be escaped:
    • VAR=VAL -> VAL
    • VAR="VAL" -> VAL
    • VAR='VAL' -> VAL
  • Inline comments for unquoted values must be preceded with a space:
    • VAR=VAL # comment -> VAL
    • VAR=VAL# not a comment -> VAL# not a comment
  • Inline comments for quoted values must follow the closing quote:
    • VAR="VAL # not a comment" -> VAL # not a comment
    • VAR="VAL" # comment -> VAL
  • Quotes can be escaped with \:
    • VAR='Let\'s go!' -> Let's go!
    • VAR="{\"hello\": \"json\"}" -> {"hello": "json"}
  • The \n, \r, \t, \\ shell escape sequences are supported in double-quoted values:
    • VAR="some\tvalue" -> some value
    • VAR='some\tvalue' -> some\tvalue
    • VAR=some\tvalue -> some\tvalue

To see examples of how files are parsed, look at the ./env_test.v and .env files.

dotenv-v's People

Contributors

bramvbilsen avatar

Watchers

 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.