Skip to content

Instantly share code, notes, and snippets.

View kousik93's full-sized avatar
💭
Infrastructure @proofpoint

Kousik Sundar kousik93

💭
Infrastructure @proofpoint
View GitHub Profile
@kousik93
kousik93 / Golang - Arbitrary JSON Array Parsing and Type Switch.md
Last active December 8, 2022 14:07
Golang - Arbitrary JSON Array Parsing and Type Switch

##Golang Type Switch - Arbitrary JSON Array Parsing I'm writing this mostly as a reference for myself. This could also be helpful to people who are new to GO.

####Note 1: Until Problem 3 we will assume we are dealing with a JSON for which we know the data types of key,value pairs. Only in Problem 3 we will look at how Type Switch is used to parse a 100% arbitary JSON

####Note 2: I know the following examples given here can be easily solved by declaring approprite structs and just decoding the PUT JSON into them, but, as im not able to come up with a better scenario, im going to stick with this to explain arbitrary JSON parsing.

@kousik93
kousik93 / The curious case of Go lang variable naming convention.md
Last active August 7, 2019 18:40
The curious case of Go lang variable naming convention

Being new to Go, I decided to try writing a very simple REST API. I'm writing here about the bizarre problem I encountered writing it and how it took me a very long time to find the solution. To professional Go programmers this might sound very trivial. But coming from a background of mainstream OO langages, I found this pretty unconventional.

So lets look at a simple program that handles a http POST request. The request sends along some JSON data. Usually to store and parse JSON data you create a struct similar to the structure of the incoming JSON and decode the JSON and store it in an object of the struct. Lets have a look at a sample code:

type test_struct struct {
	Test string `json:"test"`
}