A .env file in the working directory is now optional
This commit is contained in:
1 parent
0b1952bd69
commit
1e3acaeff3
5 files changed
+30
-9
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user