Independent Consultant
Course Description
Get a quick introduction to Go. Learn basic syntax like variables, constants, data types, and creating and importing packages. You’ll get hands-on with functions, control structures, error handling, type definitions, structures, and interfaces. Create a webserver which handles API requests and uses Go templates. Finally, see a few advanced topics like goroutines, channels, and async API calls.
This course and others like it are available as part of our Frontend Masters video subscription.
Preview
CloseWhat They're Saying
I just finished watching Max Firtman's Basics of Go course on Frontend Masters. It's one of the best, full of easy-to-understand examples, helpful tips, and best practices! It was my first interaction with Go and I can't wait to dive deeper into the waters of Go! Thank You!
Samuel Hovančák
s_hovancak
"Go fundamentals" by Max Firtman on Frontend Masters was the best Go course. Gave me a strong foundation and then went on to build stuff on my own.
Vinayak Goyal
ivinayakg
"Basics of Go" by Max Firtman on Frontend Masters closed gaps in my understanding and knowledge of Golang, especially with go routines and channels. Now I have a decent understanding to learn further and build on top of this.
Vinayak Goyal
ivinayakg
Course Details
Published: August 8, 2023
Learning Paths
Topics
Learn Straight from the Experts Who Shape the Modern Web
Your Path to Senior Developer and Beyond
- 200+ In-depth courses
- 18 Learning Paths
- Industry Leading Experts
- Live Interactive Workshops
Table of Contents
Introduction
Section Duration: 3 minutes
- Maximiliano Firtman introduces the course by sharing some personal and professional background. The overview includes key topics covered, such as Go fundamentals, standard libraries, goroutines, the fmt package, the http package, templating, and web servers, providing a clear outline of the course content.
What is Go
Section Duration: 52 minutes
- Maximiliano provides a brief overview and history of Go including its connection to Golang. The discussion highlights the three main goals of the Go language: ease of coding, efficient compilation, and efficient execution.
- Maximiliano explores the key characteristics of Go, such as its static type system, garbage collection, and single binary compilation. The discussion also includes an overview of the timeline of Go, starting from its inception in 2007 to the release of Go 1.20 in 2023, providing a glimpse into the evolution of the language over time.
- Maximiliano guides students through the official Go website and explains the organization of its documentation. The discussion includes a brief demonstration of the Tour of Go tutorial and an overview of the learning resources available.
- Maximiliano explores companies that use Go and the main values of the language. The discussion also covers the capabilities of the Go CLI and the tooling required for developing Go applications.
- Maximiliano walks through selecting the appropriate Go extension for Visual Studio Code, checking Go installation, and creating a basic stand-alone Go script. The discussion also covers how to run the Go script from the terminal.
- Maximiliano explores the multi-platform capabilities of Go, highlighting its ability to generate executable binary files for various platforms and operating systems. The discussion further covers common use cases for Go, such as web services, DevOps, desktop UI, and machine learning.
Variables, Constants, and Data Types
Section Duration: 1 hour, 9 minutes
- Maximiliano discusses fundamental syntax rules of Go, emphasizing the use of curly braces to contain code blocks, the case-sensitivity of the language, and its non-object-oriented nature without classes. The discussion further covers essential rules governing the contents of folders and files in Go.
- Maximiliano showcases the process of creating and running a module using the Go command-line interface (CLI). The discussion also covers the topic of creating multi-module applications using workspaces.
- Maximiliano explains the syntax for defining variables, constants, and data types in Go. The discussion also highlights Go's capability to infer data types and introduces a shortcut for defining variables.
- Maximiliano demonstrates Go's pre-defined data types, including strings, booleans, and numeric types like integers and floating-point values. The discussion also addresses student questions about defining constants globally and Go's ability to automatically determine a variable's data type.
- Maximiliano covers the topic of defining and importing packages in Go, explaining the scope of functions within these packages. The discussion includes a demonstration using dot syntax to access data from imported packages and how to define public or private visibility.
- Maximiliano demonstrates helpful functionality in VS Code for importing packages and performing linting in Go development. The discussion also covers a student's question about exporting data from packages other than the main package.
- Maximiliano gives a concise overview of visibility in Go, explaining the concepts of defining public or private elements and discussing the various scoping options for variables and lambda functions.
- Maximiliano explores the usage of global functions for converting between different number types in Go, and introduces collections such as arrays, slices, and maps. It is important to note that collections in Go are not objects and can be manipulated using global functions.
Functions, Control Structures, & Error Handling
Section Duration: 1 hour, 22 minutes
- Maximiliano highlights the characteristics of functions in Go, emphasizing their capability to return multiple values and use labeled variables. The segment includes a demonstration of how to handle functions that return multiple variables.
- Maximiliano showcases the usage of pointers in Go, which allows creating references to the original value of a passed variable. It's important to note that unless a reference is used, Go automatically creates a copy of the passed variable.
- Maximiliano demonstrates Go's less common control flow mechanisms, panic and defer, along with design patterns for error handling. These mechanisms involve triggering runtime errors, halting program execution, and deferring function evaluations.
- Maximiliano explores Go's commonly used control structures, including if, for, and switch, highlighting the differences in formatting compared to JavaScript. The switch structure is particularly useful as it can include conditions and serve as a replacement for extensive if statements.
- Maximiliano guides you through the process of creating a basic calculator in Go, which takes input from the standard input using Scanf. Additionally, different verb types for the fmt package functions are explained in this segment.
- Maximiliano showcases the usage of os.ReadFile to read the contents of a text file, and provides guidance on handling errors that may occur during a failed read attempt.
- Maximiliano illustrates the process of writing a file using os.WriteFile and creating more intricate messages with fmt.Sprintf. The segment also addresses a student's question about whether package names and directories must match.
Type Definitions, Structures, & Interfaces
Section Duration: 1 hour, 22 minutes
- Maximiliano showcases the declaration of new types, the addition of methods to types, and referencing types using aliases. However, it is important to note that methods cannot be attached to type aliases.
- Maximiliano addresses a student's question about defining methods with string types and provides an additional example that demonstrates defining types with an attached method to clarify the purpose of the attribute arguments.
- Maximiliano explores structures, which are data types that have strongly typed properties, default constructors, and the ability to include methods.
- Maximiliano demonstrates creating a data structure and explains how to import and access the structure data in a different package. It is important to make the properties of the data structure public in order to access them.
- Maximiliano showcases patterns for creating factory functions that generate instances of structs or interfaces. These factory functions encapsulate the creation logic and offer a convenient way to construct instances of complex or customizable types.
- Maximiliano demonstrates implementing a method that modifies the default output of a type to a customized string format.
- Maximiliano showcases type embedding, allowing the parent type to inherit the properties of the embedded type. The segment also covers accessing the embedded data in a factory function.
- Maximiliano demonstrates how to create interfaces in Go, which define a set of methods that can be used as a type. Interfaces in Go have implicit implementation and can emulate polymorphism commonly found in object-oriented programming.
- Maximiliano discusses goroutines, which are Go's way of utilizing threads, and demonstrates how to open a goroutine using the "go" prefix. This segment also covers delaying thread execution using time.Sleep.
- Maximiliano demonstrates creating channels for inter-goroutine communication and addresses a student's question about passing channels between multiple packages. Buffer channels are also introduced to control the number of values that can be sent at once.
Creating an API Client
Section Duration: 1 hour, 32 minutes
- Maximiliano walks through setting up the initial packages for a console application that utilizes the cex.go package to make API requests and retrieve data.
- Maximiliano demonstrates the usage of the strings package to perform basic operations on UTF-8 encoded strings, such as manipulation and transformation. It's important to note that these functions generate a new copy of the string and do not modify the original.
- Maximiliano showcases the creation of response and error handlers using the built-in HTTP status codes provided by the Go http package. These handlers are useful for managing and handling various HTTP responses and errors in a Go application.
- Maximiliano demonstrates how to make an API call from the main package and showcases the format of the returned data.
- Maximiliano demonstrates the process of parsing and storing JSON data using the Unmarshal function from the json package. The Unmarshal function decodes the JSON-encoded data and saves the result in the provided value, which should be a pointer.
- Maximiliano creates a Go struct that aligns with the API's JSON response structure, using a JSON-to-Go converter tool. It emphasizes that if the property types in the struct do not match the JSON data, the Unmarshal function will raise an error.
- Maximiliano illustrates that the order of API data returned from a Get call is a synchronous operation. Additionally, the segment discusses utilizing waiting groups to wait for a collection of goroutines to finish.
- Maximiliano demonstrates the creation of a lambda function that functions as a GoRoutine, allowing for the containment and synchronous execution of API calls. This approach enables efficient handling and coordination of API requests within the Go program.
- Maximiliano explores Go's built-in testing capabilities, including defining test suites, testing functions, and Go fuzzing. Fuzzing, a form of automated testing that systematically manipulates program inputs to uncover bugs, is also covered in this segment.
Creating a Server
Section Duration: 1 hour, 31 minutes
- Maximiliano provides an overview of options for utilizing Go in web development, such as WebAssembly, transpiling to JavaScript, web servers, and web services. Additionally, a step-by-step guide on setting up a basic local HTTP server is included in this segment.
- Maximiliano addresses a student's question about enabling debugging and demonstrates the process of moving the server function outside of the main function. The segment also mentions that Go does not provide a built-in tool for automatically restarting the server when a file changes, requiring the use of a third-party tool.
- Maximiliano demonstrates the usage of the FileServer utility function to create a file server that automatically searches the specified directory for files to be served.
- Maximiliano explores the usage of Go templates for server-side rendering, emphasizing their ability to generate dynamic content like HTML or configuration files. By separating the presentation logic from the data, Go templates facilitate easier management and updates.
- Maximiliano responds to student inquiries about the required imports and clarifies whether the dot in the template represents a type. Additionally, the segment includes a demonstration of serving a museum exhibition from a data structure.
- Maximiliano showcases the usage of the range keyword to iterate over the existing data structure and dynamically render the remaining museum exhibitions. The segment also covers the conditional rendering of HTML using if-else statements.
- Maximiliano illustrates the process of creating handlers to make API GET requests and retrieve all the requested items. The segment also covers the handling of request errors and demonstrates how to request data by ID.
- Maximiliano demonstrates the process of creating a handler for handling API POST requests. The segment covers the handling of POST errors and includes a practical demonstration of a successful POST request.
- Maximiliano discusses the benefits of using frameworks and external libraries to simplify the process of building applications in Go. The segment includes the implementation of the Gin web framework as an example to demonstrate how frameworks or external libraries can be utilized in Go development.
- Maximiliano covers the process of compiling a Go project, including the flexibility to compile for various platforms and operating systems. Additionally, in order to embed an application's assets, a package needs to be created, as Go produces binary files through compilation.
Wrapping Up
Section Duration: 2 minutes
- Maximiliano wraps up the course by providing an overview of the material covered and addressing a student's question about the typical usage of Go in development.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops