Skip to content

Commit

Permalink
refactor: improve if
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 1, 2021
1 parent 2ed4d36 commit e244b8a
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,6 @@ func get(field reflect.StructField, opts []Options) (val string, err error) {
}

defaultValue, defExists := field.Tag.Lookup("envDefault")
if key == "" {
if defExists {
return defaultValue, nil
}
return "", nil
}

val, exists = getOr(key, defaultValue, defExists, getEnvironment(opts))

if expand {
Expand Down Expand Up @@ -287,7 +280,7 @@ func getFromFile(filename string) (value string, err error) {
func getOr(key, defaultValue string, defExists bool, envs map[string]string) (value string, exists bool) {
value, exists = envs[key]
switch {
case !exists && defExists:
case (!exists || key == "") && defExists:
return defaultValue, true
case !exists:
return "", false
Expand Down

0 comments on commit e244b8a

Please sign in to comment.