Categorygithub.com/tsivinsky/goenv
repositorypackage
1.1.0
Repository: https://github.com/tsivinsky/goenv.git
Documentation: pkg.go.dev

# README

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)