Skip to content

uulwake/godotenvsafe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

godotenvsafe CI Go Report Card Go Version Go Reference

A package to help you to check missing environment variable before running your app and getting unnecessary runtime error.

It uses godotenv under the hood to load your environment variables. This package will make sure that you don't miss any env vars.

Installation

go get github.com/uulwake/godotenvsafe

Usage

For example below is .env file.

DB_NAME=db-name
DB_USER=user
DB_PASSWORD=pass

Then create .env.template with the key only like below.

DB_NAME=
DB_USER=
DB_PASSWORD=

Then you can load your environment variables safely like this.

import (
    "log"

    "github.com/uulwake/godotenvsafe"
)

func main() {
    err := godotenvsafe.Load(".env")
    if err != nil {
        log.Fatal("Error loading env variables", err.Error())
    }
}

Conventions

This package will automatically search for env template by adding suffix .template in your env file. Some examples like below:

Env file Env Template File
.env .env.template
.env.local .env.local.template
.env.development .env.development.template
.env.testing .env.testing.template
.env.prod .env.prod.template

About

A package to help you load environment variables safely

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages