String or *string


(Gligor Gudjevski) #1

i have a func that return (string, error)
and if there is an error inside the func i am returning "", err
is that good or i should change it to return (*string, err)
and to return nil, err


(Holloway) #2

Up to you whether you want to make use of nil. However, the latter (string pointer) is very uncommon so it might confuse people. Normally as a practice, whenever err != nil, we discards the use of that value regardless whether it is valid or otherwise.

Unlike other data type, string is always re-created so there isn’t a point to use string pointer except variable manipulation for function’s pass as pointer.