loading...
Cover image for Day 3 of #30DaysOfCode | struct and pointer in Go

Day 3 of #30DaysOfCode | struct and pointer in Go

shubhamsaurav profile image Shubham Saurav 惻2 min read

Whenever you are working on a project of any significance, you are going to have to work with collections of Data. The different programming languages have different solutions to approach that problem. Javascript has Object, Python has Dictionaries to deal with collections of data and Go has Struct(struct) for this job.

Struct(struct) is short for structure and is a data structure in Go to store collections of properties that are related.

Today, on the third day of #30DaysOfCode challenge I learnt about structs. One thing that you should learn from this post is that Go is a value type. So whenever you are passing a struct on a function, Go is making a copy of that struct and not actually passing the reference of the value in the memory. If you are coming from a Reference Type language like Javascript then you really need to be careful about this while writing Go code.

Sometimes, when you are changing the value of the struct with receiver function it will not work as you are expecting it to because again Go is Value Type language. But there is a workaround this problem. You can use Pointers.

Pointers can solve this problem but it is confusing and we will talk about that in the next post.
So, please follow to receive my next post firsthand.

Connect With Me:
Youtube: ShubhamSauravYT.
Twitter: @hiShubhamSaurav
Instagram: @hiShubhamSaurav
Facebook: @hiShubhamSaurav

Posted on by:

shubhamsaurav profile

Shubham Saurav

@shubhamsaurav

Writing Restful APIs using JS. Learning to code in Go(Golang)

Discussion

markdown guide