equal
deleted
inserted
replaced
1 # gotenv |
1 # gotenv |
2 |
2 |
3 [![Build Status](https://travis-ci.org/subosito/gotenv.svg?branch=master)](https://travis-ci.org/subosito/gotenv) |
3 [![Build Status](https://github.com/subosito/gotenv/workflows/Go%20workflow/badge.svg)](https://github.com/subosito/gotenv/actions) |
4 [![Build status](https://ci.appveyor.com/api/projects/status/wb2e075xkfl0m0v2/branch/master?svg=true)](https://ci.appveyor.com/project/subosito/gotenv/branch/master) |
|
5 [![Coverage Status](https://badgen.net/codecov/c/github/subosito/gotenv)](https://codecov.io/gh/subosito/gotenv) |
4 [![Coverage Status](https://badgen.net/codecov/c/github/subosito/gotenv)](https://codecov.io/gh/subosito/gotenv) |
6 [![Go Report Card](https://goreportcard.com/badge/github.com/subosito/gotenv)](https://goreportcard.com/report/github.com/subosito/gotenv) |
5 [![Go Report Card](https://goreportcard.com/badge/github.com/subosito/gotenv)](https://goreportcard.com/report/github.com/subosito/gotenv) |
7 [![GoDoc](https://godoc.org/github.com/subosito/gotenv?status.svg)](https://godoc.org/github.com/subosito/gotenv) |
6 [![GoDoc](https://godoc.org/github.com/subosito/gotenv?status.svg)](https://godoc.org/github.com/subosito/gotenv) |
8 |
7 |
9 Load environment variables dynamically in Go. |
8 Load environment variables from `.env` or `io.Reader` in Go. |
10 |
9 |
11 ## Usage |
10 ## Usage |
12 |
11 |
13 Put the gotenv package on your `import` statement: |
12 Put the gotenv package on your `import` statement: |
14 |
13 |
27 |
26 |
28 Once loaded you can use `os.Getenv()` to get the value of the variable. |
27 Once loaded you can use `os.Getenv()` to get the value of the variable. |
29 |
28 |
30 Let's say you have `.env` file: |
29 Let's say you have `.env` file: |
31 |
30 |
32 ``` |
31 ```sh |
33 APP_ID=1234567 |
32 APP_ID=1234567 |
34 APP_SECRET=abcdef |
33 APP_SECRET=abcdef |
35 ``` |
34 ``` |
36 |
35 |
37 Here's the example of your app: |
36 Here's the example of your app: |
77 Besides above functions, `gotenv` also provides another functions that overrides existing: |
76 Besides above functions, `gotenv` also provides another functions that overrides existing: |
78 |
77 |
79 - `gotenv.OverLoad` |
78 - `gotenv.OverLoad` |
80 - `gotenv.OverApply` |
79 - `gotenv.OverApply` |
81 |
80 |
82 |
|
83 Here's the example of this overrides behavior: |
81 Here's the example of this overrides behavior: |
84 |
82 |
85 ```go |
83 ```go |
86 os.Setenv("HELLO", "world") |
84 os.Setenv("HELLO", "world") |
87 |
85 |
118 // import "strings" |
116 // import "strings" |
119 |
117 |
120 pairs := gotenv.Parse(strings.NewReader("FOO=test\nBAR=$FOO")) |
118 pairs := gotenv.Parse(strings.NewReader("FOO=test\nBAR=$FOO")) |
121 // gotenv.Env{"FOO": "test", "BAR": "test"} |
119 // gotenv.Env{"FOO": "test", "BAR": "test"} |
122 |
120 |
123 err, pairs = gotenv.StrictParse(strings.NewReader(`FOO="bar"`)) |
121 pairs, err := gotenv.StrictParse(strings.NewReader(`FOO="bar"`)) |
124 // gotenv.Env{"FOO": "bar"} |
122 // gotenv.Env{"FOO": "bar"} |
125 ``` |
123 ``` |
126 |
124 |
127 `Parse` ignores invalid lines and returns `Env` of valid environment variables, while `StrictParse` returns an error for invalid lines. |
125 `Parse` ignores invalid lines and returns `Env` of valid environment variables, while `StrictParse` returns an error for invalid lines. |
128 |
126 |