Giter Club home page Giter Club logo

Comments (4)

erka avatar erka commented on June 11, 2024

Hi @bnewbold.

My idea would be a bit different that you expect. I would like to discuss it before making PR with changes .

I believe .env file will be used only in development environment and make file be great tool here.
It maybe sound extreme but I would suggest to move environment variables setup to Makefile. It could be done but adding

ifneq (,$(wildcard ./.env))
    include .env
    export
endif

to the top of Makefile.

Making this change will solve the issue with GOLOG_LOG_LEVEL, cleanup the copy and paste code below from each command and allow to remove godotenv from the project

	// only try dotenv if it exists
	if _, err := os.Stat(".env"); err == nil {
		err := godotenv.Load()
		if err != nil {
			log.Fatal("Error loading .env file")
		}
	}

What do you think about it?

from indigo.

bnewbold avatar bnewbold commented on June 11, 2024

I've never tried parsing a .env from a Makefile. Does it work? Does it parse the file as Makefile syntax? I'm not sure if that is a problem or not, might be fine.

The Makefile on it's own wouldn't help with things like go run or use of fakermaker and gosky CLIs, which I at least run frequently with different args and rely on .env for basic auth and config. It is possible to use a separate wrapper command like dotenv (apt get install dotenv on Debian), or we could have CLI tools load .env and service commands not.

It is a bit weird to have the daemon processes look for .env on every invocation, but I also don't think it is causing any problems. I think the GOLOG_LOG_LEVEL issue is probably a trivial one-line fix, I just haven't gotten around to testing it. So, overall, feel this is low priority.

from indigo.

bnewbold avatar bnewbold commented on June 11, 2024

I found a nice fix using import _ "github.com/joho/godotenv/autoload", which reduces boilerplate and works at package init() time, so it can out-race the logging setup. It does still look for a .env always, but i'm going to prefer that fix for now.

from indigo.

erka avatar erka commented on June 11, 2024

@bnewbold It's the great solution. Please take a look on PR.

from indigo.

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.