Skip to content

Commit

Permalink
Don't abort loading .env files in when first one fails
Browse files Browse the repository at this point in the history
  • Loading branch information
florensie committed Dec 31, 2020
1 parent 4cfd204 commit bb78c83
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ func main() {
log.Printf("Looking for .env file in %s", exPath)

// Load config and initialize
err = godotenv.Load(".env", filepath.Join(exPath, ".env"))
if err != nil && !os.IsNotExist(err) {
log.Fatalf("error loading .env file(s): %s", reflect.TypeOf(err))
}
tryLoadDotEnv(filepath.Join(exPath, ".env"), ".env")

keepAmount, err = strconv.Atoi(os.Getenv("KEEP_AMOUNT"))
if err != nil {
Expand All @@ -59,6 +56,16 @@ func main() {
}
}

//tryLoadDotEnv load dot env files but don't abort when one doesn't exist
func tryLoadDotEnv(filenames ...string) {
for _, filename := range filenames {
err := godotenv.Load(filename)
if err != nil && !os.IsNotExist(err) {
log.Fatalf("error loading .env file: %s", reflect.TypeOf(err))
}
}
}

func createBackup(server *hcloud.Server) {
log.Printf("creating backup for %s\n", server.Name)

Expand Down

0 comments on commit bb78c83

Please sign in to comment.