WEEK 7: ENTRY 1
It sometimes feels like we are not good enough when our tries don’t work. Well at my internship today, I worked on resolving the json unmarshalling issue I was stuck with last Friday. After several back-and-forth consultations with my buddy and manager, I finally got a better understanding of how they wanted me to present the data. Basically, the data should be in a simple json array that could be manipulated easier. This is because as the json comes in key:pair format, I would need to extract all the keys and use those keys to send an HTTPS request to Elasticsearch Rest API.
Even though the approach was well defined and clear to me, I still struggled to implement it using the Golang Struct and Maps. One of the obstacles I had was because after unmarshalling the json data, the output was in a Golang interface type, which was not iterable like say a slice. A Golang slice is the equivalent of a python array. Therefore, to overcome that barrier, I created an empty slice with type interface and appended all the output to it. That way, it would be easy to iterate through the slice and get the respective values. You might think that would have solved all the issues, unfortunately no it didn’t. It did work for the first interface output because they were only two fixed outputs, but the second interface can have several values. I was so frustrated and tired at this point because it did seem that the more I worked on it, the more I got more issues.
So then I asked myself what next? Luckily, my buddy came to my cubicle and was like “do you still need some hints,”and I was like yes I do. He suggested using a Golang struct because it would be easier to map those values into key-value pairs using the struct. To be honest, that resolved my issue like magic. I was both satisfied and disappointed because my subconscious mind should have thought about that, but it didn’t. I learned a lot from this roadblock and I intend to be more technical in my approach and ask relevant questions in the future because it has shown time and time again that doing these two saves time and helps to troubleshoot the issue quicker
Comments
Post a Comment