https://github.com/marlonmp/dotenv
This is a package for loads env files
https://github.com/marlonmp/dotenv
dotenv golang
Last synced: 5 months ago
JSON representation
This is a package for loads env files
- Host: GitHub
- URL: https://github.com/marlonmp/dotenv
- Owner: marlonmp
- Created: 2022-03-30T15:09:26.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-30T15:40:29.000Z (about 4 years ago)
- Last Synced: 2024-06-20T06:23:22.973Z (about 2 years ago)
- Topics: dotenv, golang
- Language: Go
- Homepage:
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dotenv
Loads the env file in a Golang map
> Big O notation: O(n)
## Usage
```bash
# .env
NAME=SomeName wrong_value # some comment
KEY="--- Your key here ---" # secret key
# empty variables
EMPTY_VARIABLE=
```
```golang
// config/env.go
import "github.com/marlonmp/dotenv"
var env map[string]string
// loads the env file wherever you want
func init() {
envPath := "path/to/.env/file"
dotenv.LoadFile(envPath, &env)
}
// create your own `GetEnv`
func Env(idx string) string {
return env[idx]
}
// main.go
import "packageName/config"
func main() {
name := config.Env("NAME")
println("Hello", name) // Hello SomeName
}
```
Happy hacking ;)