Comments (4)
If I understand @lesichkovm correctly he would like to have a function which simplifies the following:
val, ok := os.LookupEnv("KEY")
if !ok {
val = "DEFAULT_VAL"
}
Instead of the above code you could write this:
val := godotenv.Env("KEY", "DEFAULT_VAL")
from godotenv.
@lesichkovm, I think there is a similar logic provided already. When you call the Load(filenames ...string) or Overload(filenames ...string), it first calls on filenamesOrDefault(filenames); If "filenames" is empty, a fallback is provided. This fallback expects to find ".env" file in the root folder.
from godotenv.
@D-sense it is not about loading files, but a helper function to check if an environmental variable exists:
myVar := Env("MYENV", "DEFAULT_IF_NOT_SET")
from godotenv.
@lesichkovm , please ignore the tagging of the PR. It was a mistake (I didn’t mean to tag it here).
On the point you raised, except I still haven’t gotten your point well enough, I think the existing logic already caters for that need (as outlined in my earlier response). I might be wrong though.
from godotenv.
Related Issues (20)
- Create ARM release for godotenv binary? HOT 3
- godotenv is "complete" and not accepting feature requests HOT 1
- Expanding variable value
- expanding command line interface or linking to sister project
- How to set default value in yaml file
- dotenv does not report an error if file does not exist HOT 2
- Variables in dotenv file starting with capital letter when they shouldn't
- Bugs in parser around unquoted whitespace and newlines in v1.5.0 HOT 10
- `-` is not supported in the key from version 1.5 but is supported in 1.4. Can we please take a look here ? This is a very basic use case. HOT 2
- Variable in the form `VAR="${VAR:-default}"` does not parse correctly
- Getting double quotes in values in env file HOT 2
- .env: no such file or directory HOT 5
- Inline comments in .env breaks builds for linux amd64
- How tu use godotenv when testing implemented? HOT 2
- Failed to parse when yaml document delimiter is present
- LICENCE file is mispelled HOT 1
- There was a problem using the command "go install github.com/joho/godotenv/cmd/godotenv@latest" HOT 1
- inconsisting case handling across different OS HOT 1
- extractVarValue assumes a quote is escaped if a backslash precedes it, even if the backslash is escaped
- (possible) bug in parser right-trimming escaped quotes?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godotenv.