Golang Object-Oriented Programming

Everything you wanted to know about structs in Golang

Mayank Gupta
TechnoFunnel

--

This article is focused on working with object-oriented architecture in Golang. We don’t have classes in Golang, so the only way to support the object-oriented model is to work with structs.

Creating Structs in Golang

Structs can be used to represent a complex object comprising multiple key-value pairs.

Let's look for a scenario: We want to represent an employee in our organization. In order to represent an employee, we require a combination of key-value pairs containing all of the the employee-related data. The employee entity can be comprised of multiple keys/properties, such as Name, Age, Designation, and Salary. All of these attributes/properties collectively represent a single employee in our organization.

Let's create a simple Employee dtruct with basic data properties.

The above code contains the following building blocks:

  1. The type keyword can be used to…

--

--

Mayank Gupta
TechnoFunnel

9 Years of Experience with Front-end Technologies and MEAN Stack. Working on all Major UI Frameworks like React, Angular and Vue https://medium.com/technofunnel