How to use the "unsafe" or "reflect" package to do type conversions in Go? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to use the "unsafe" or "reflect" package to do type conversions in Go?

I need to convert the output from a function which has interface{} type to a struct. I tried doing type casting and it won't work. So I tried to lookup on the Internet and found unsafe and reflect to be used for this purpose but I'm not able to understand how to use them and what's their inner workings. Can somebody explain this? P.S don't ask me to Google things, I have done it for almost 2 hours for this.

29th Dec 2020, 6:02 PM
anon
0 Answers