Viper: Support for .env files?

Created on 7 Feb 2018  Â·  13Comments  Â·  Source: spf13/viper

Is there support for a feature like provided by this library?

Basically if .env file exists it will read variables from there, otherwise from OS.

Most helpful comment

@sagikazarmark @boskiv
though PR is merged but not in latest release
when will have new release?

All 13 comments

Someone already submits a PR here, #528
Look forward to this support

How I can get it? I see that it already merge but not in release.
I'm using GOMODULES, I don't know how to set version to master there.

/Users/i_skiridomov/Projects/tmp/go-open-registry/go.mod:8: invalid module version "master": module lookup disabled by -mod=vendor

Adding master to a go.mod file is not valid indeed.

You should use:

go get github.com/spf13/viper@master

I can't

➜  go-open-registry git:(git-registry) ✗ go get
go get: disabled by -mod=vendor

add missing ability to find .env or other dotfiles
RP #756

EX:

viper.AddConfigPath(PATH_TO_FIND)
viper.SetConfigName("")
viper.SetConfigType("env")
err = viper.ReadInConfig()

@sagikazarmark @boskiv
though PR is merged but not in latest release
when will have new release?

What is the current situation here? Is there any conclusion or progress?

+1

Would love to see this feature in viper

Unless I'm mistaken #528 added support for .env files and it's been released for quite some time now.

Unless I'm mistaken #528 added support for .env files and it's been released for quite some time now.

@sagikazarmark is there any documentation on how to use it?

I set the config type to dotenv and I get an error saying its not a supported type.

.env and .dotenv types are working similarly to any config types. Looking at the code, you'll have to set an explicit config file if you want to use .env. A file called config.env should automatically be discovered.

.env and .dotenv types are working similarly to any config types. Looking at the code, you'll have to set an explicit config file if you want to use .env. A file called config.env should automatically be discovered.

I see. I will test it out later today and will report if I was able to get it to work.

Thanks for the quick response.

@sagikazarmark it worked! Now I'm able to read from a file called config.env which holds all the secret data.

Thank you :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TimJones picture TimJones  Â·  4Comments

GrapeBaBa picture GrapeBaBa  Â·  5Comments

michaeleekk picture michaeleekk  Â·  3Comments

kubaugustyn picture kubaugustyn  Â·  3Comments

TWinsnes picture TWinsnes  Â·  3Comments