go-defaults
go-defaults copied to clipboard
Default value for slice of struct isn't working for me
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: &{[]}
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