Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Apr 30, 2024
1 parent 4f5aa25 commit 236bfa0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions confmap/confmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type Conf struct {
k *koanf.Koanf
// If true, upon unmarshaling do not call the Unmarshal function on the struct
// if it implements Unmarshaler and is the top-level struct.
// This avoids running into a circular dependency.
// This avoids running into an infinite recursion where Unmarshaler.Unmarshal and
// Conf.Unmarshal would call each other.
skipTopLevelUnmarshaler bool
}

Expand Down Expand Up @@ -327,7 +328,8 @@ func unmarshalerHookFunc(result any, skipTopLevelUnmarshaler bool) mapstructure.
}

toPtr := to.Addr().Interface()
// Need to ignore the top structure to avoid circular dependency.
// Need to ignore the top structure to avoid running into an infinite recursion
// where Unmarshaler.Unmarshal and Conf.Unmarshal would call each other.
if toPtr == result && skipTopLevelUnmarshaler {
return from.Interface(), nil
}
Expand Down

0 comments on commit 236bfa0

Please sign in to comment.