Skip to content

Commit 6d02a84

Browse files
committed
👔 up: envutil - dotenv add new option: LoadFirstExist
1 parent 0107e47 commit 6d02a84

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

envutil/dotenv.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Dotenv struct {
2828
//
2929
// - default: false - will return error if not exists
3030
IgnoreNotExist bool
31+
// LoadFirstExist only load first exists env file on Files
32+
LoadFirstExist bool
3133

3234
loadFiles []string
3335
loadData map[string]string
@@ -72,6 +74,9 @@ func (c *Dotenv) doLoadFiles(files []string) error {
7274
if err := c.loadFile(filePath); err != nil {
7375
return err
7476
}
77+
if c.LoadFirstExist && len(c.loadFiles) > 0 {
78+
break
79+
}
7580
}
7681

7782
return nil
@@ -186,3 +191,8 @@ func LoadEnvFiles(baseDir string, files ...string) error {
186191
})
187192
}
188193

194+
// LoadedEnvFiles get loaded dotenv files
195+
func LoadedEnvFiles() []string {
196+
return stdEnv.LoadedFiles()
197+
}
198+

0 commit comments

Comments
 (0)