OneBite.Dev - Coding blog in a bite size

declare a class in Go

Code snippet on how to declare a class in Go

type Student struct {
  Name string
  Age int
  Marks int
}

This piece of code declares a struct in Go language called Student, which has three fields: Name (string type), Age (integer type) and Marks (integer type). A struct is the most basic and important data type in Go language. It is used to pack together different data types so that we can group related information in one data structure. In this example, the Student struct has three fields that relate to a student’s information like name, age, and marks. This will allow us store and access student data using a single Student variable.

go