Package genvutils provides useful environment operations
IsProduction
,IsDevelopment
andIsTesting
checks forENVIRONMENT
dot env value.GetEnv
gets env value or fallback which goes as second function argument.Parse
will fill given struct with env values or with fallbacks. (see examples folder)
type serverConfig struct {
ServerPort string `genv:"SERVER_PORT,8080"`
MongoUrl string `genv:"MONGO_URL,mongodb://localhost:27017"`
}
Load
will load dotenv file. You can provide file name via argument otherwise it will load dot enviroment file by priority list. First exist - first load. Priority list:
.env.production.local`
.env.test.local`
.env.development.local`
.env.production`
.env.test`
.env.development`
.env.local`
.env`
go get -u github.com/lalabuy948/genvutils