Re: [go-nuts] check for *string that is nil

2017-08-22 Thread Dan Kortschak
OK, then I think you've answered your own question; your uses should handle the nils, rather than papering over them by assigning a pointer to "". If you expect to have "" when the value is empty, just use string. On Tue, 2017-08-22 at 17:39 -0700, Eric Brown wrote: > Yeah, sometimes it's better

Re: [go-nuts] check for *string that is nil

2017-08-22 Thread Eric Brown
Yeah, sometimes it's better to use a pointer to a string when dealing with possible null|nil values and you plan on deserializing json or yaml, which I'm doing a lot of for an api. There are a few other instances where you'd probably want to also... https://dhdersch.github.io/golang/2016/01/23

Re: [go-nuts] check for *string that is nil

2017-08-22 Thread Dan Kortschak
Is there a reason to have the fields be *string rather than just string? On Tue, 2017-08-22 at 15:48 -0700, Eric Brown wrote: > Let's say I have a struct... > > type Contact struct { >  Id    int `json:"id"` >  FirstName *string `json:"firstname"` >  LastName  *string `json:"lastname"` >

[go-nuts] check for *string that is nil

2017-08-22 Thread Eric Brown
Let's say I have a struct... type Contact struct { Idint `json:"id"` FirstName *string `json:"firstname"` LastName *string `json:"lastname"` Email *string `json:"email"` Phone *string `json:"phone"` Ext *string `json:"ext"` } I define contact... var contact Contac