Go - Structures

Go arrays allow you to define variables that can hold several data items of the same kind. Structure is another user-defined data type available in Go programming

Defining a Structure

To define a structure, you must use type and struct statements. The struct statement defines a new data type, with multiple members for your program.
type struct_variable_type struct {
   member definition;
   member definition;
   member definition;
Once a structure type is defined, it can be used to declare variables of that type using the following syntax
variable_name := structure_variable_type {value1, value2...valuen}

Accessing Structure Members

To access any member of a structure, we use the member access operator (.).
package main

import "fmt"

type School struct {
    age string
    student string
    subject string
    school_id int
func main() {
    var school1 School    /* Declare school1 of type school */
    var school2 School    /* Declare school2 of type school */

    /* school 1 specification */
    school1.age = "sixteen"
    school1.student = "Markup David"
    school1.subject = "COMPUTER SCIENCE "
    school1.school_id = 6495407

    /* school 2 specification */
    school2.age = "seventeen"
    school2.student = "Sara"
    school2.subject = "ENGLISH"
    school2.school_id = 6495700

    /* print school1 info */
    fmt.Printf( "school 1 age : %s\n", school1.age)
    fmt.Printf( "school 1 student : %s\n", school1.student)
    fmt.Printf( "school 1 subject : %s\n", school1.subject)
    fmt.Printf( "school 1 school_id : %d\n", school1.school_id)

    /* print school2 info */
    fmt.Printf( "school 2 age : %s\n", school2.age)
    fmt.Printf( "school 2 student : %s\n", school2.student)
    fmt.Printf( "school 2 subject : %s\n", school2.subject)
    fmt.Printf( "school 2 school_id : %d\n", school2.school_id)
When the above code is compiled and executed, it produces the following result
school 1 age : sixteen
school 1 student : Markup David
school 1 subject : COMPUTER SCIENCE 
school 1 school_id : 6495407
school 2 age : seventeen
school 2 student : Sara
school 2 subject : ENGLISH
school 2 school_id : 6495700

Pointers to Structures

You can define pointers to structures in the same way as you define pointer to any other variable as follows
var struct_pointer *Books
you can store the address of a structure variable in the above defined pointer variable. To find the address of a structure variable