Code Monkey home page Code Monkey logo

godotenv's Introduction

godotenv

Go dot env lib. Some of other go dot env library doesn't support go embed feature , so you can NOT embed the static file into go build executable binaries. This lib is a standard repo which support this feature, once you integrate with this repo, you can just simply run go build as usually we do, you don't need to care that you need to copy the static files to somewhere manually.

Usage

go get github.com/driftprogramming/[email protected]

Example

see godotenv_test.go in current repo Or see this:

.

├── envs.go // example here                    
├── envs               # local, dev, test, live env files.
│   ├──.env           # common env variables, which will be loaded in all other envs
│   ├──.env.dev       # dev env variables
│   ├──.env.live      # live env variables
│   ├──.env.local     # local env variables
│   └──.env.test      # test env variables
└── ...
// envs/.env.local
version=local.1.0
otherkey=abcd
// envs/.env.live
version=live.1.0
// envs.go
package root

import (
	"embed"

	"github.com/driftprogramming/godotenv"
)

//go:embed envs/*
var envs embed.FS

func SetupExample(env string) {
	_ = godotenv.Load(envs, "envs/.env.live")
	version1 := godotenv.Get("version") // version1 will be live.1.0

	// the below method will not overwrite if env key already existed.
	_ = godotenv.LoadWithoutOverwrite(envs, "envs/.env.local")
	version2 := godotenv.Get("version") // version2 will still be live.1.0

	_ = godotenv.Load(envs, "envs/.env.local")
	version3 := godotenv.Get("version") // version3 will be local.1.0
}

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.