Git Product home page Git Product logo

gotenv's People

Contributors

5nord avatar arroyoh avatar atomaths avatar bios-marcel avatar deiz avatar legec avatar luisdavim avatar subosito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gotenv's Issues

OverLoad: local variables do not override environment variables

When using override functions like OverLoad local variables do not override environment variables anymore, since #12.

Example 1

$ export A="fromEnv"
$ cat .env
A="fromFile"
B="$A"

Expected Behaviour

After using OverLoad, variable B should have value fromFile.

Actual Behaviour

Variable B has value fromEnv.

Example 2: Recursive variable expansion

$ export B="fromEnv"
$ cat .env
A="$B$C"
B="fromFile"
C="fnord"

What is the expected behaviour, when a reference is resolved before its definition? I would argue it should be fromEnv,
since gotenv evaluates environment files line by line.

Unclear specification in Usage instructions

I found the Usage section in instructions to be a bit unclear:

Store your configuration to .env file on your root directory of your project

This may not always be the case. As many go projects are made up of multiple executables.
In my specific scenario:
I have a rootdir and the subsequent directories rootdir/cmd/someWebService and rootdir/cmd/clock, where clock is a simple ticker for the web-service.

As I've come to understand after messing around with gotenv for a while, what it actually does is reading files in directories relative to the file taking use of gotenv.Load()

Coming back to my scenario, I have to specify a relative path in gotenv.Load(...) for each of my executables. This is honestly not actually a bad thing, as it allows for more flexibility in my go code and file/folder structure. The point I'm trying to make is rather this: The Usage instructions doesn't specify in a good manner where it reads from.

  • Thank you

multiline ENV variable?

Do you have any plans to support multiline ENV variables?
linePattern regex already supports it, but bufio.NewScanner(r) produces variable splitted by new line separator and makes it invalid before linePattern applied.

1.5.0 Breaks spf13/viper

Just updated dependencies in one of our projects and noticed that builds are now failing on gotenv 1.5.0. This may be a problem with upstream packages but thought I would start here. The package throwing the error is spf13/viper

The following error appears during builds. The viper version did not change.

/go/pkg/mod/github.com/spf13/[email protected]/internal/encoding/dotenv/codec.go:51:33: cannot use &buf (value of type *bytes.Buffer) as gotenv.Reader value in argument to gotenv.StrictParse: *bytes.Buffer does not implement gotenv.Reader (missing method ReadAt)
failed to build, error: exit status 1

equal sign (=) character support

I'm trying to add a cert to .env file like this:
CERT: "-----BEGIN CERTIFICATE-----\nMIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLh==........โ€

but it doesn't works if there is equal sign = character in the value

Any suggestion?

Documentation incorrect for return values of StrictParse

The documentation for the StrictParse method is done incorrectly. The return values are swapped between the actual error and the map returned. It is currently documented as

err, pairs = gotenv.StrictParse(strings.NewReader(`FOO="bar"`))

which should have been below as per the function definition

pairs, err = gotenv.StrictParse(strings.NewReader(`FOO="bar"`))

The swapped order could be potentially confusing, but not a major one.

UTF16-LE files can't be parsed

I have written a .env file via PowerShell, using echo "X=Z" >> file.env. This produces a UTF16 file with a little endian BOM byte encoded in UTF-16.

I will try to fix this with a PR.

ENV Reset

Firstly, thank you for the library. It works beautifully!

The one thing I find missing is a reset option with this library. In testing I've found once the environment is set during testing it is impossible to reset the environment with the tool that modified it. I can write my own code for the testing but it would be nice to just call gotenv.Reset(). ๐Ÿ‘ผ

Ignore missing files and options

I wanted to be able to ignore missing .env file, because I sometimes directly load environment variable without using the .env file (docker, or else ...).

So I wonder whether this package is open to add such options or if you want to keep it simple stupid ? Meaning that I will have to check if the files exists myself before loading.

Therefore I'd like to propose a extra LoadWithOptions function that allows on to define options such as IgnoreMissingFiles.

Unexpected behaviour when referencing variables

When resolving variable references definitions in environment file take precedence over environment variables.

Example

$ export A="fromEnv"
$ cat .env
A="fromFile"
B="$A"

Expected behavior

After loading environment file, variable B should have value fromEnv.

Current behavior

After loading environment file, variable B has value fromFile

StrictParse ignores scanner.Scan errors

When reading the input buffer to parse the env, the returning method is ignoring any errors that might have occurred on the scanning process, if no line is read. We stumbled upon this while trying to read huge files that hit the scanner token limit, which was causing the scanner error ErrTooLong to be returned, thus failing to read the buffer.

https://github.com/subosito/gotenv/blob/master/gotenv.go#L211

Should check for the scanner result with scanner.Err() method before returning here

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.