Skip to content

Commit

Permalink
Return when trying to (Over)Load empty Map
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed Feb 21, 2024
1 parent 6662303 commit c447c1f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ func LoadEnv(key string, val Value) error {
// Load sets the environment variables from the Map using Environment.Set when
// they do not exist.
func Load(environ Map) error {
if len(environ) == 0 {
return nil
}

return (&Loader{ReplaceVars: true}).Load(environ)
}

// Overload sets and overwrites the environment variables from the Map using
// Environment.Set.
func Overload(environ Map) error {
if len(environ) == 0 {
return nil
}

return (&Loader{Overload: true, ReplaceVars: true}).Load(environ)
}

Expand All @@ -43,6 +51,10 @@ func NewLoader(dest Environment) *Loader {
// Load sets the environment variables from the Map using os.Setenv when they
// do not exist.
func (l *Loader) Load(m Map) error {
if len(m) == 0 {
return nil
}

if l.environ == nil {
l.environ = environ
}
Expand Down

0 comments on commit c447c1f

Please sign in to comment.