Giter Club home page Giter Club logo

Comments (8)

joho avatar joho commented on July 17, 2024

A good question, let me try and figure out

  1. What we do
  2. What we should do (ie what does the ruby lib do)

from godotenv.

joho avatar joho commented on July 17, 2024
 ~/Projects/dotenvtest  ruby test.rb 
xTvDqw
foo$bar
123value
 ~/Projects/dotenvtest  BAR=other ruby test.rb 
xTvDqw
foo$bar
123other
 ~/Projects/dotenvtest  vim test.go 
 ~/Projects/dotenvtest  go run test.go
xTvDqw7
foo\
123value
 ~/Projects/dotenvtest  BAR=other go run test.go
xTvDqw7
foo\
123value

Environment variables should take preference (but don't), though there will probably be some edge cases in load vs overload.

Guess there's a 1.3.1 coming soon 😄

from godotenv.

coolaj86 avatar coolaj86 commented on July 17, 2024

Had this discussion with a coworker and he told me the same.

Each time a .env is loaded the prior takes precedence.

The rationale being

  • secrets go in memory only
  • .env.{dev,testing,staging,prod) have the endpoints go same tier services
  • .env (local) has personal preference for local dev and doesn’t get committed

from godotenv.

coolaj86 avatar coolaj86 commented on July 17, 2024

Thanks for looking into that and I look forward to the new version

from godotenv.

coolaj86 avatar coolaj86 commented on July 17, 2024

poke => v1.3.1 with precedence fixes?

from godotenv.

joho avatar joho commented on July 17, 2024

Hey sorry - hell of a hectic week as a sole startup founder and haven't been able to jump straight on this. Will try today or tomorrow. PRs always welcome if you need to hurry it along more than that.

from godotenv.

coolaj86 avatar coolaj86 commented on July 17, 2024

I starting digging into the code and it looked as if everything was in order.

I ran a test to be sure and it seems to me that all is working as it should:

test.go:

package main

import (
	"fmt"
	"os"

	"github.com/joho/godotenv"
)

func main() {
	os.Setenv("QUX", "nowyouseeme")
	godotenv.Load()
	godotenv.Load("second.env", "third.env")

	fmt.Printf("FOO=%s (%s)\n", os.Getenv("FOO"), "\"nowyouseeme\"")
	fmt.Printf("BAR=%s (%s)\n", os.Getenv("BAR"), "\"nowyouseeme\"")
	fmt.Printf("BAZ=%s (%s)\n", os.Getenv("BAZ"), "\"nowyouseeme\"")
	fmt.Printf("QUX=%s (%s)\n", os.Getenv("QUX"), "\"nowyouseeme\"")
	fmt.Printf("QUUX=%s (%s)\n", os.Getenv("QUUX"), "\"\"")
}

.env:

FOO=nowyouseeme
QUX=NOWYOUDONT

second.env:

FOO=NOWYOUDONT
BAR=nowyouseeme

third.env:

FOO=NOWYOUDONT2
BAR=NOWYOUDONT
BAZ=nowyouseeme

go run test.go:

# actual test results vs hard-coded expectation
FOO=nowyouseeme ("nowyouseeme")
BAR=nowyouseeme ("nowyouseeme")
BAZ=nowyouseeme ("nowyouseeme")
QUX=nowyouseeme ("nowyouseeme")
QUUX= ("")

FOO=DOUBLECHECKING go run test.go:

# result for FOO is preferring the existing environment, as expected
FOO=DOUBLECHECKING ("nowyouseeme")
BAR=nowyouseeme ("nowyouseeme")
BAZ=nowyouseeme ("nowyouseeme")
QUX=nowyouseeme ("nowyouseeme")
QUUX= ("")

from godotenv.

coolaj86 avatar coolaj86 commented on July 17, 2024

Here are some suggestions for updating the REAME: #60

from godotenv.

Related Issues (20)

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.