feat: load env from file

main
Urko 3 months ago
parent d815b12719
commit e77a67a3de

@ -27,9 +27,9 @@ var envConfig struct {
var writer pkgio.WriterIface
func intEnvConfig(isProd bool) {
if !isProd {
err := godotenv.Load(util.RootDir() + "/.env")
func intEnvConfig(envFilePath string) {
if envFilePath != "" {
err := godotenv.Load(envFilePath)
if err != nil {
log.Fatalf("environment variable ENV is empty and an error occurred while loading the .env file: %s\n", err)
}
@ -134,7 +134,12 @@ func exportPem(filename string, data []byte) (string, error) {
}
func init() {
intEnvConfig(false)
envFile := ""
if os.Getenv("ENV") != "prod" {
envFile = "./.env"
}
intEnvConfig(envFile)
cobra.OnInitialize(initConfig)
}

@ -44,8 +44,8 @@ func init() {
func Test_exportPem(t *testing.T) {
defer func() {
os.Remove(testFile)
// err := os.Remove(testFile)
// require.NoError(t, err)
err := os.Remove(testFile)
require.NoError(t, err)
}()
data := []byte("test data")

Loading…
Cancel
Save