Hi, some simple leads,
Use one line initialization of Person p := &Person{Attr:&Attribute{}} Enhance the if conditions statement if p.Attr != nil && p.Attr.Age < 10 { fmt.Println("Too Young") } Use a Person constructor func NewPerson() &Person { return &Person{Attr:&Attribute{}} } I, too, dislike that default values for struct pointer properties is nil. On Friday, January 13, 2017 at 2:26:12 PM UTC+1, mail...@gmail.com wrote: > > > Hello, > > Have been struggling with mitigating against nil pointer deference and i > would appreciate if anyone can help > > Code 1: Works file > https://play.golang.org/p/lhOh9g5R9l > > > Code 2: Error > https://play.golang.org/p/pY4F9bK-D9 > > > How do you validate Attr was set if its a pointer ? > > Thanks In Advance > Teety > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.