I'm designing an interface and wonder, what's the more idiomatic way:
func GetUser(id string) (*User, error)
or
func GetUser(id string, u *User) error
I'm designing an interface and wonder, what's the more idiomatic way:
func GetUser(id string) (*User, error)
or
func GetUser(id string, u *User) error
Depends on the intended purpose.
If the purpose is to — given an identifier — fetch the information
about the user and fill a user-supplied variable (of an appropriate type)
with that information, then it's the case for
func GetUser(id string, u *User) error
.
If the purpose is to fetch that information and create a new value
(of an appropriate type) containing that information and return it
(or — as in your case — a pointer to it) to the user, then it's the case
for func GetUser(id string) (*User, error)
.
So, in the end, it's not about comparing "idiomaticity factor" of the two solutions; they capture different ways to deal with the obtained data.