Jay Taylor's notesback to listing index
Golang - Get pointer to value using reflection[web search]
I have a function that iterates through all fields of an interface passed as parameter. In order to achieve this is I am using reflection. The issue is that I do not know how to obtain the address of a non-pointer field. Here is an example:
The above code represents my test structures. Now here is the actual function which traverses a specified structure and lists details about it:
And here is the actual test after structure instantiation/initialization:
And finally the output of InspectStruct call:
As you can see I am using recursion, so if one of the fields is a struct kind then I call InspectStruct for it. My issue is that though all fields have been initialized for the entire structure "t" hierarchy, I am not able to get the address for any field located at a higher depth than "t". I would really appreciate any help.
Working example : http://play.golang.org/p/nleA2YWMj8
I was going to leave this as a comment on OneOfOne's post, but it turned out a little too complex for a comment and very relevant to answering the question and why OneOfOne's answer works correctly.
However, think about the
As you'll note, passing a value directly to
So, in our example above, if we were to naively pass in
So why does passing the
All it can give you is this
Not the answer you're looking for? Browse other questions tagged
go or ask your own question.
1 year ago
- Sports/eSports Team Hiring Senior Full StackVantage SportsWORK REMOTELYgodocker
Get the weekly newsletter!
- Top questions and answers
- Important announcements
- Unanswered questions
see an example newsletter
Hot Network Questions
- What makes E-bomb or Electromagnetic pulse (EMP) destructive?
- Elementary, Dr. Watson; it's a console adventure
- What could cause the water flow in house pipes to suddenly be altered?
- Genuine SOQL Injection issue or False Positive?
- Why does reboot and poweroff require root privileges?
- What would you say to bosses that think programming jobs are interchangeable?
- How to compensate for weather changes in barometric pressure sensor (BMP180)?
- Magical internet - unique addressing system
- Does this series of primes converge?
- Can wood dust cause irritation to other people in the house?
- How do Han and Chewie find Rey and Finn in the Millennium Falcon?
- What happened to C3P0's red arm?
- Plot a transfer function in latex
- Word for someone who says yes, then no, then yes
- How can I politely turn down the exit interview?
- What is an adjective for a person who constantly speaks negatively?
- Is it possible to have a button inside a column in Sharepoint list
- Adding the probabilities of two events when one is a subset of the other
- Why is plagiarism so harshly punished?
- How would people tell time if it was always day?
- What does the letter at the end of a tire code signify?
- Is commuting 10 km on an empty stomach harmful?
- Print 1 to 15, using different printers
- Direct voting on every issue (referendum) - new political system
|Technology||Life / Arts||Culture / Recreation||Science||Other|