Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structs.InitDefaults: No skip default in nested structs #173

Open
d-enk opened this issue May 14, 2024 · 0 comments
Open

structs.InitDefaults: No skip default in nested structs #173

d-enk opened this issue May 14, 2024 · 0 comments
Assignees

Comments

@d-enk
Copy link

d-enk commented May 14, 2024

  • OS: linux
  • GO Version: 1.22.3
  • Pkg Version: 0.6.15
package main

import "github.com/gookit/goutil/structs"

func maint() {
	type Nested struct {
		Age int `default:"1"`
	}

	type Config struct {
		Age int `default:"1"`

		Slice []Nested // `default:""`

		Nested // `default:""`
	}

	c := Config{
		Slice: []Nested{{}, {}},
	}

	structs.InitDefaults(&c)

	fmt.Printf("%+v\n", c)
	// {Age:1 Slice:[{Age:0} {Age:0}] Nested:{Age:0}}
	// expected {Age:1 Slice:[{Age:1} {Age:1}] Nested:{Age:1}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants