Answer the question
In order to leave comments, you need to log in
How to iterate over a structure in a loop?
Hello everyone
There is a structure with 23 fields, with int64 and float64 types. It is necessary to perform a mathematical operation with each field, plus or minus (depending on the specific user action). How can this be done?
I see it in such a way that there is a function where the structure object and the value to be added are supplied. But I can't figure out how to bypass each field of the strutkra. Let me know if anyone has experienced or knows
Answer the question
In order to leave comments, you need to log in
GO is a language with static typing, the type of operands is calculated during compilation, how can it "bypass the structure" to do different (by type of operands) operations? Answer: You will prompt him, with pens, in all 23 cases.
This can be done through the reflect package, but if you need it, then something is wrong in the architecture of your program and you are trying to transfer the experience of scripting languages to go. Do not do it this way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question