Hello Hay,
with interface{} you explicitly allow everything. Instead you may consider
to restrict the accepted input in the first place - e.g. with a non-empty
interface.
Chrishay <[email protected]> schrieb am Mo. 19. Nov. 2018 um 15:37: > Hi, > > I've the following example code of correct version. > > func SomeFunction(itemPtr interface{}) { > > > //itemPtr must be pointer to struct and not struct. > > > } > > > func SomeFunctionCaller() { > > > u := UserRecord{} > > > SomeFunction(&u) > > > } > > > Above is the correct version, but some coders pass struct instead of > pointer which causes run-time errors. > > Bad version: > > func SomeFunctionCaller() { > > > u := UserRecord{} > > > SomeFunction(u) > > > } > > > Is there a way to force "SomeFunction" to take pointers only at compile > time? > > Thanks and best regards, > > -- > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
