Skip to content

Load env variables to struct

Notifications You must be signed in to change notification settings

tsivinsky/goenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goenv

Install

go get -u github.com/tsivinsky/goenv

Example

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 for loading variables from .env file

Rules

required

type Env struct {
    VAR string `env:"VAR,required"`
}

This will result in runtime error if VAR env doesn't exist

default=

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)

About

Load env variables to struct

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages