25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Structs in Go

June 4, 2021
Elliot Forbes

Elliot Forbes

Course Instructor

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

In this video, we are going to be looking at structs in Go and what they are used for.

Overview

package main

import "fmt"

type Engineer struct {
	Name    string
	Age     int
	Project Project
}

type Project struct {
	Name         string
	Priority     string
	Technologies []string
}

func main() {
	fmt.Println("Structs Tutorial")

	engineer := Engineer{
		Name: "Elliot",
		Age:  27,
		Project: Project{
			Name:         "Beginner's Guide to Go",
			Priority:     "High",
			Technologies: []string{"Go"},
		},
	}
	fmt.Printf("%+v\n", engineer)

	fmt.Println(engineer.Project.Name)

}

Output

$ go run main.go
Structs Tutorial
{Name:Elliot Age:27 Project:{Name:Beginner's Guide to Go Priority:High Technologies:[Go]}}
Beginner's Guide to Go