A minimalistic pkg to load environment variables to strct
get it :
go get -u github.com/kamalshkeir/kenv@latest
Example:
Struct to Fill from env
typeGlobalConfigstruct {
Hoststring`kenv:"HOST|localhost"`// DEFAULT to 'localhost': if HOST not found in envPortstring`kenv:"PORT|9313"`Embedstruct {
Staticbool`kenv:"EMBED_STATIC|false"`Templatesbool`kenv:"EMBED_TEMPLATES|false"`
}
Dbstruct {
Namestring`kenv:"DB_NAME|db"`Typestring`kenv:"DB_TYPE"`// REEQUIRED: this env var is required, you will have error if emptyDSNstring`kenv:"DB_DSN|"`// NOT REQUIRED: if DB_DSN not found it's not required, it's ok to stay empty
}
Smtpstruct {
Emailstring`kenv:"SMTP_EMAIL|"`Passstring`kenv:"SMTP_PASS|"`Hoststring`kenv:"SMTP_HOST|"`Portstring`kenv:"SMTP_PORT|"`
}
Profilerbool`kenv:"PROFILER|false"`Docsbool`kenv:"DOCS|false"`Logsbool`kenv:"LOGS|false"`Monitoringbool`kenv:"MONITORING|false"`
}
Fill
kenv.Load(".env") // load env files and add to env vars// the command:err:=kenv.Fill(&Config) // fill struct with env vars loaded before
About
A minimalistic golang pkg to load environment variables to strct