You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 12, 2022. It is now read-only.
A Go (golang) port of the Ruby dotenv project (which loads env vars from a .env file)
4
4
@@ -8,181 +8,5 @@ From the original Library:
8
8
>
9
9
> But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a .env file into ENV when the environment is bootstrapped.
10
10
11
-
It can be used as a library (for loading in env for your own daemons etc) or as a bin command.
11
+
This is a fork of [joho/godotenv](https://github.com/joho/godotenv) focussing on `.env` file support by the compose specification
12
12
13
-
There is test coverage and CI for both linuxish and windows environments, but I make no guarantees about the bin version working on windows.
14
-
15
-
## Installation
16
-
17
-
As a library
18
-
19
-
```shell
20
-
go get github.com/joho/godotenv
21
-
```
22
-
23
-
or if you want to use it as a bin command
24
-
```shell
25
-
go get github.com/joho/godotenv/cmd/godotenv
26
-
```
27
-
28
-
## Usage
29
-
30
-
Add your application configuration to your `.env` file in the root of your project:
31
-
32
-
```shell
33
-
S3_BUCKET=YOURS3BUCKET
34
-
SECRET_KEY=YOURSECRETKEYGOESHERE
35
-
```
36
-
37
-
Then in your Go app you can do something like
38
-
39
-
```go
40
-
package main
41
-
42
-
import (
43
-
"github.com/joho/godotenv"
44
-
"log"
45
-
"os"
46
-
)
47
-
48
-
funcmain() {
49
-
err:= godotenv.Load()
50
-
if err != nil {
51
-
log.Fatal("Error loading .env file")
52
-
}
53
-
54
-
s3Bucket:= os.Getenv("S3_BUCKET")
55
-
secretKey:= os.Getenv("SECRET_KEY")
56
-
57
-
// now do something with s3 or whatever
58
-
}
59
-
```
60
-
61
-
If you're even lazier than that, you can just take advantage of the autoload package which will read in `.env` on import
62
-
63
-
```go
64
-
import _ "github.com/joho/godotenv/autoload"
65
-
```
66
-
67
-
While `.env` in the project root is the default, you don't have to be constrained, both examples below are 100% legit
The original library [dotenv](https://github.com/bkeepers/dotenv) was written by [Brandon Keepers](http://opensoul.org/), and this port was done by [John Barton](https://johnbarton.co/) based off the tests/fixtures in the original library.
0 commit comments