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
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
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"`
>
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