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/golang-when-to-use-string-pointers.html

On Tuesday, August 22, 2017 at 7:31:55 PM UTC-5, kortschak wrote:
>
> 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"` 
> >  Email     *string `json:"email"` 
> >  Phone     *string `json:"phone"` 
> >  Ext       *string `json:"ext"` 
> > } 
> > 
>
>
>
>

-- 
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.

Reply via email to