Skip to content

Commit

Permalink
update init vars to only apply to structs
Browse files Browse the repository at this point in the history
  • Loading branch information
sethpollack committed Jan 2, 2025
1 parent f23f15d commit 563bdf2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ Config:
> ```
### Init Options
- `vars` - Initialize when vars are present (default)
- `any` - Initialize when vars are present or default values are provided.
- `vars` - Initialize when values are present with the exception of structs that only have default values. (default)
- `any` - Same as `vars`, but also initialize structs that only have default values.
- `always` - Always initialize
- `never` - Never initialize
Expand Down
9 changes: 6 additions & 3 deletions internal/walker/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ func (w *Walker) visit(v *Value) error {
return err
}

if initMode == InitVars && !tmp.IsSet {
return nil
if tmp.Kind() == reflect.Struct {
if initMode == InitVars && !tmp.IsSet {
return nil
}
}

if initMode == InitAny && (!tmp.IsSet && !tmp.IsDefault) {
// never init empty pointers unless init mode is always
if initMode != InitAlways && (!tmp.IsSet && !tmp.IsDefault) {
return nil
}

Expand Down

0 comments on commit 563bdf2

Please sign in to comment.