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

Default value for slice of struct isn't working for me #9

Open
pavankumar-bit opened this issue Oct 10, 2019 · 1 comment
Open

Default value for slice of struct isn't working for me #9

pavankumar-bit opened this issue Oct 10, 2019 · 1 comment

Comments

@pavankumar-bit
Copy link

pavankumar-bit commented Oct 10, 2019

package main

import (
	"fmt"

	"gopkg.in/mcuadros/go-defaults.v1"
)

func main() {

	foo := &Parent{}
	defaults.SetDefaults(foo)
	fmt.Print(foo)
}

type Child struct {
	Name string
	Age  int `default:"10"`
}

type Parent struct {
	Children []Child
}

output: &{[]}

@pavankumar-bit pavankumar-bit changed the title Default value for slice of struct doesn't seem to be working for me Default value for slice of struct isn't working for me Oct 10, 2019
@huty1998
Copy link

	foo := &Parent{
		Children: []Child{{}},
	}

probably you need to write like that to set the default value for ONE Child{} of Children cause Children is a slice @pavankumar-bit

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