GOLANG

Structures in Go (structs)

Unlike traditional Object-Oriented Programming, Go does not have class-object architecture. Rather, we have structures that hold complex data structures.

Uday Hiwarale
RunGo
Published in
14 min readOct 19, 2018

--

(source: pexels.com)

What is a struct?

A struct or structure can be compared with the class in the Object-Oriented Programming paradigm. If you don’t know what OOP is, then imagine struct being a recipe that declares the ingredients and the kind of each ingredient.

A structure has different fields of the same or different data types. If you compare structure with a recipe, field names of the structure become the ingredients (like salt) and field types become the kind of these ingredients (like table salt).

A structure is used mainly when you need to define a schema made of different individual fields (properties). Like a class, we can create an object from this schema (class is analogous to the schema).

Since we can instantiate a structure, there should be some nomenclature distinction between the structure and the instance. Hence, the name struct type is used to represent the structure schema and struct or structure is used to represent the instance.

--

--