[go-nuts] Re: How do you mitigate against nil pointer dereference

2017-01-13 Thread mailteety
Hello, Thanks for the response. The Major Issue is that am getting the Data from *json *and its inconsistent. Regards Teety On Friday, 13 January 2017 14:41:02 UTC+1, mhh...@gmail.com wrote: > > Hi, > > some simple leads, > > Use one line initialization of Person > p := &Person{Attr:&Attribute{

Re: [go-nuts] Re: How do you mitigate against nil pointer dereference

2017-01-13 Thread Henrik Johansson
Expose properties as methods and do the check in the method can make the caller use easier. On Fri, Jan 13, 2017, 14:41 wrote: > Hi, > > some simple leads, > > Use one line initialization of Person > p := &Person{Attr:&Attribute{}} > > Enhance the if conditions statement > if p.Attr != nil &

[go-nuts] Re: How do you mitigate against nil pointer dereference

2017-01-13 Thread mhhcbon
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:&Attribut