[Golang] Get To Know More About Struct On Golang

Struct is a collection of variables or functions that have various data types. in the go programming language, we can create new variables using structs. the use of structs is usually done to make it easier to call data.

Writing a struct begins with a type then continues with the name of the struct.

The employee structure consists of the name variable and also the age variable. The name variable has a string data type, while the age variable has an integer data type.

The employee variable is a filled struct. In the example above, the variable name in the employee struct is filled with Asdam in the form of a string. while the age variable is filled with the number 10 which is an integer.

Struct with various data type

We can also use the array data type in the struct property. so that we can add a lot of data in one property or struct variable.

In the example above, we add 1 skill variable in the form of an array

The code above displays the multivalue skill which is part of the employee struct with type data array.

Struct with array data type

In addition, writing data types on struct properties can also be obtained from other structs.

We add a department struct which contains the DepartmentName property with the string data type. And in the employee struct, we add the department obtained from the struct department.

In the code above, displays the employee department data where the data is obtained from different structs.

Struct with from another struct

Finally, we already know about structs in the go programming language. after we know the struct we can apply the struct to the service we will create.




All about go language

Recommended from Medium

Role of Documentation and Software Architecture in Cubix

Ansible: an easy way to start with config management

Building A Secured Web API With .Net Core 3.1 & Jason Web Tokens

Net Core + JWT

Unify email signatures across your employees using Typeform and Zapier

An Intro to Max 7

Exporting PostgreSQL Data to Excel with Python

eric ~ Vulnhub | Writeup

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amiruddin Saddam

Amiruddin Saddam

Backend Engineer at Jamtangan.com And will always learn something new.

More from Medium

Robust media upload with Golang and Cloudinary — Echo Version

Mocking HTTP Call in Golang a Better Way

Photo by @jim_reardan on Unsplash

Echo 101: Get service metadata from Web UI

【Go】Implement SHA256, encryption and hashing in Go