Skip to content

Commit

Permalink
fix: skip fields without env key in onSet (#266)
Browse files Browse the repository at this point in the history
Options.OnSet gets called on _all_ fields, even the ones that _don't_
have an `env` key defined. This simply ignore those.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
  • Loading branch information
aymanbagabas committed May 12, 2023
1 parent 3f7d8cf commit 0b4d8a6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion env.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ func get(field reflect.StructField, opts Options) (val string, err error) {
}

if opts.OnSet != nil {
opts.OnSet(key, val, isDefault)
if ownKey != "" {
opts.OnSet(key, val, isDefault)
}
}
return val, err
}
Expand Down

0 comments on commit 0b4d8a6

Please sign in to comment.