Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deeper-x/goenv
manage dotenv .env parameters from golang
https://github.com/deeper-x/goenv
dotenv dotenv-parser golang
Last synced: 18 days ago
JSON representation
manage dotenv .env parameters from golang
- Host: GitHub
- URL: https://github.com/deeper-x/goenv
- Owner: deeper-x
- Created: 2023-09-17T13:39:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-21T17:05:27.000Z (7 months ago)
- Last Synced: 2024-05-22T18:07:47.204Z (7 months ago)
- Topics: dotenv, dotenv-parser, golang
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Golang Dot Env
Handle .env parameters in golang.
Usage:
Step 1 - Install:
```sh
go get -v github.com/deeper-x/goenv@latest
```Step 2 - Create an .env:
```txt
USER=demo_user
PASSWORD=qwerty
```Step 3 - Deploy:
```golang
package mainimport (
"fmt"
"github.com/deeper-x/goenv"
)func main() {
cfo, err := goenv.New(".env")
if err != nil {
panic(err)
}username, err := cfo.Get("USERNAME")
if err != nil {
panic(err)
}password, err := cfo.Get("PASSWORD")
if err != nil {
panic(err)
}fmt.Printf("user: %s; password: %s", username, password)
}// Output:
// user: demo_user; password: qwerty
```Test:
```golang
go test -v ./...
```### Details
Build file object:
```golang
efo, err := goenv.New() // <-- access default .env file in current dir, or New("./assets/.env") for custom file path
if err != nil {
panic(err)
}
```
Inspect file content:
```golang
fc, err := FileDump()
if err != nil {
panic(err)
}fmt.Println(fc)
```Access .env parameters:
```golang
v, err = cfo.Get("USERNAME")
if err == nil {
panic("...handle error...")
}fmt.Println(v) // <-- access environment value
```PLEASE NOTE: Accessing non existing variables raises an error!
```golang
efo, err := goenv.New()
if err != nil {
panic(err)
}v, err = efo.Get("NON_EXISTING")
if err != nil {
panic("handle error on non-existing key fetched")
}
```