https://github.com/tsivinsky/goenv
Load env variables to struct
https://github.com/tsivinsky/goenv
env go goenv
Last synced: 5 months ago
JSON representation
Load env variables to struct
- Host: GitHub
- URL: https://github.com/tsivinsky/goenv
- Owner: tsivinsky
- Created: 2023-02-06T13:39:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-03-20T21:09:51.000Z (about 1 year ago)
- Last Synced: 2025-03-20T22:23:54.580Z (about 1 year ago)
- Topics: env, go, goenv
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# goenv
## Install
```bash
go get -u github.com/tsivinsky/goenv
```
## Example
```go
package main
import (
"github.com/tsivinsky/goenv"
)
type Env struct {
APP_NAME string `env:"APP_NAME"`
}
func main() {
env := new(Env)
goenv.Load(env)
}
```
Under the hood, `goenv` use [godotenv](https://github.com/joho/godotenv) for loading variables from .env file
## Rules
### `required`
```go
type Env struct {
VAR string `env:"VAR,required"`
}
```
This will result in runtime error if VAR env doesn't exist
### `default=`
```go
type Env struct {
VAR string `env:"VAR,default=var`
}
```
This will set value for `Env.VAR` as `var` if no other value is provided (including empty string)