From ece06ff4323c2a2def2fd523e20ea553d24b7646 Mon Sep 17 00:00:00 2001 From: roeldev Date: Sat, 6 Apr 2024 20:08:48 +0200 Subject: [PATCH] Fix panic at dotenv (over)loading --- dotenv/load.go | 14 ++------------ dotenv/read.go | 2 ++ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/dotenv/load.go b/dotenv/load.go index 1ab0d97..77bb46b 100644 --- a/dotenv/load.go +++ b/dotenv/load.go @@ -9,36 +9,26 @@ import ( "io/fs" ) -const panicNilFsys = "dotenv: fs.FS must not be nil" - // Load sets the environment variables from the active environment using // env.Load. func Load(dir string, ae ActiveEnvironment) error { - return env.Load(ReadFS(nil, dir, ae)) + return env.Load(Read(dir, ae)) } // Overload sets and overwrites the environment variables from the active // environment using env.Overload. func Overload(dir string, ae ActiveEnvironment) error { - return env.Overload(ReadFS(nil, dir, ae)) + return env.Overload(Read(dir, ae)) } // LoadFS sets the environment variables from the active environment using // env.Load. func LoadFS(fsys fs.FS, dir string, ae ActiveEnvironment) error { - if fsys == nil { - panic(panicNilFsys) - } - return env.Load(ReadFS(fsys, dir, ae)) } // OverloadFS sets and overwrites the environment variables from the active // environment using env.Overload. func OverloadFS(fsys fs.FS, dir string, ae ActiveEnvironment) error { - if fsys == nil { - panic(panicNilFsys) - } - return env.Overload(ReadFS(fsys, dir, ae)) } diff --git a/dotenv/read.go b/dotenv/read.go index 7e29cce..6734afb 100644 --- a/dotenv/read.go +++ b/dotenv/read.go @@ -48,6 +48,8 @@ func Read(dir string, ae ActiveEnvironment) *Reader { return newReader(nil, dir, ae) } +const panicNilFsys = "dotenv: fs.FS must not be nil" + // ReadFS reads .env files at dir from fsys, depending on the provided // ActiveEnvironment. func ReadFS(fsys fs.FS, dir string, ae ActiveEnvironment) *Reader {