A .env file in the working directory is now optional

This commit is contained in:
bwilliams committed 2026-10-21 15:28:52 +01:00
1 parent 0b1952bd69
commit 1e3acaeff3
5 files changed
+30 -9

No files matched your search

+7 -2
View File
@@ -3,6 +3,7 @@ package config
import (
"errors"
"fmt"
"io/fs"
"log/slog"
"os"
"strings"
@@ -34,9 +35,13 @@ func isExplicitlySet(key string) bool {
}
// loadEnv loads environment variables from a .env file in the working
// directory.
// directory, if there is one. One that can't be read or parsed is an error.
func loadEnv() error {
if err := godotenv.Load(); err != nil {
err := godotenv.Load()
if errors.Is(err, fs.ErrNotExist) {
return nil
}
if err != nil {
return fmt.Errorf("invalid .env file: %w", err)
}
return nil