Skip to content

Commit

Permalink
skip field if value is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
profclems committed Oct 12, 2024
1 parent 1bfc22e commit ec4e885
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ func (e *DotEnv) Unmarshal(v any) (err error) {

if fieldVal.CanAddr() {
if m, ok := fieldVal.Addr().Interface().(encoding.TextUnmarshaler); ok {
val := getConfigVal()
if val == "" {
continue
}
if err := m.UnmarshalText([]byte(getConfigVal())); err != nil {
return err
}
Expand All @@ -248,6 +252,9 @@ func (e *DotEnv) Unmarshal(v any) (err error) {
}

configVal := getConfigVal()
if configVal == "" {
continue
}

// set the value based on the field type
switch field.Type {
Expand Down

0 comments on commit ec4e885

Please sign in to comment.