Skip to content

Loads env vars from an .env file and current environment to your config struct.

License

Notifications You must be signed in to change notification settings

acatec/env2config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

env2config

Loads env vars from a .env file and current environment to your config struct.

Vars from .env file will override current environmental variables.

thanks to https://github.com/joho/godotenv and https://github.com/caarlos0/env

env2config is just wrapper on over these perfect libraries

Installation

As a library

go get github.com/acatec/env2config

or using dep

 dep ensure -add github.com/acatec/env2config

Usage

Add your application configuration to your .env file in the root of your project:

PORT=8080
APP_NAME=My go app

Then in your Go app you can do something like

package main

import (
    "github.com/acatec/env2config"
)

type Config struct {
	Port string `env:"PORT" envDefault:"80"`
	AppName string `env:"APP_NAME" envDefault:"noname"`
}

func main() {
	
	var cfg Config
	_ = env2config.PrepareConfig(&cfg)

    // now do something with cfg.Port and cfg.AppName
}

And if you have few env files:

_ = env2config.PrepareConfig(&cfg, "first.env", "second.env")

About

Loads env vars from an .env file and current environment to your config struct.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages