This course has been updated! We now recommend you take the Basics of Go course.
Table of Contents
IntroductionBrenna Martenson gives an overview of the course, and a brief history of the Go language.
Installing GoBrenna describes the steps for installing Go, how to set up directories using the bash profile, and how to run a Go file in the terminal to verify everything is installed correctly.
DocumentationBrenna gives an overview of the Golang documentation, and gives suggestions about how to navigate it.
Go Documentation PracticeBrenna discusses the first exercise of the course, which is a practice in exploring the Go Documentation.
Anatomy of a Go FileBrenna describes the structure of a Go file, how to run the file from the terminal, and answers questions about package main and the main() function indispensable in every runnable Go file.
Printing with fmtBrenna navigates to the Go playground and explains how to print to standard output.
Printing ExerciseBrenna demonstrates how to access the local Go documentation from the terminal, and introduces the exercise on printing.
Printing SolutionBrenna live codes the solution for the exercise.
Basic Go Syntax
TypesBrenna introduces Go syntax by giving examples of primitive types, and demonstrates how to verify a type using reflect.TypeOf.
VariablesBrenna covers a few examples of variables, describes variable syntax, and explains zero values, which are assigned when a variable is declared without an initial value.
Control Structures: If & ElseBrenna demonstrates how blocks are written in Go, how to handle an error returned from a function, and a common way to handle errors using an if block.
Control Structures: Switch StatementsBrenna demonstrates how to use switch statements in Go, explains that it is possible to use a conditional statement within switch, and illustrates how to use fallthrough inside of a case.
Control Structures: For LoopsBrenna introduces the structure of the for loop, explains its syntax, and demonstrates how to loop over a string using range.
Control Structures ExerciseBrenna reviews the control structures discussed in this section, then students are instructed to to iterate over a sentence using range, printing letters with odd indices. The blank identifier is introduced.
Control Structures SolutionBrenna live codes the solution to the exercise.
Functions & Variadic FunctionsBrenna demonstrates how to build functions containing for loops, how to name returned variables within the function signature, and how to create variadic functions that take a varying amount of arguments.
Functions ExerciseStudents are instructed to practice writing functions by creating an average function, and then refactoring the function to be variadic.
Functions SolutionBrenna live codes the solution to the exercise.
ArraysBrenna defines an array, explains array syntax in Go, and builds a for loop that iterates over the array.
MakeBrenna explains how the built-in method make works, and how it allocates memory.
SlicesBrenna explains that a slice is a form of array in Go, demonstrates how to modify its length, and then goes over how to append an element to a slice.
MapsBrenna introduces maps in Go, a data structure which is made up of key value pairs.
Complex Structures ExerciseStudents are instructed to practice working with arrays, slices and maps by completing the different parts of the complex structures exercise.
Complex Structures SolutionBrenna live codes the solution to the exercise.
Tools & CommandsBrenna introduces common Go terminal commands, such as "go run" and "go install", and demonstrates how they might be used in a Go project.
PackagesBrenna introduces the required package name at the top of every Go file, exported and unexported functions, the linting rules for exported functions, and explains how to run exported functions in other Go packages.
TestingBrenna introduces the testing package that is built into the Go standard library, then gives an example of a test function and discusses the naming conventions of a test file.
Unit Testing ExerciseStudents are instructed to write a new unit test to ensure a preexisting function runs as expected, and then to use test-driven development (TDD) to write code to make a preexisting test pass.
Unit Testing SolutionBrenna live codes the solution to the exercise.
StructsBrenna introduces structs in Go and demonstrates how to define a type on a struct, how to instantiate a struct using a struct literal, and how to access fields on a struct with dot notation.
Custom TypesBrenna demonstrates how to nest structs inside of other structs, and how to create custom types.
Accessing Nested StructsBrenna codes an example of how to instantiate a nested struct using a struct literal, then demonstrates how to access the values through the parent struct.
Modifying Struct Values ExerciseStudents are instructed to modify the existing code to change an existing field on a struct if a condition is met. Brenna gives helpful hints, and also asks students to draw conclusions on why a phenomenon is happening in the code.
Modifying Struct Values SolutionBrenna live codes the solution to the struct exercise, and foreshadows the coming chapter on pointers and references.
PointersBrenna introduces pointers by demonstrating how they allow explicit pass by reference as opposed to pass by value. An example is given on how to to point to a specific memory address of a value, and how to dereference the address to get the value stored at the memory address.
Pass by ReferenceBrenna live codes an example that highlights the difference between passing by value and passing by reference, and demonstrates how struct values can be modified.
Pointers ExerciseStudents are instructed to write a function that takes in a pointer variable and uses it to modify the value the pointer is pointing to.
Pointers SolutionBrenna live codes the solution to the exercise.
Error HandlingBrenna gives an overview of the different types of error handling in Go, namely error and panic.
Panic, Defer & Recover PracticeBrenna goes over a practice of the different error handling methods in Go: what a function should defer to when there is an error, when a function should panic, and how a function can recover from a panic.
MethodsBrenna introduces methods in Go by distinguishing them from functions.
Methods ExerciseStudents are instructed to refactor functions from earlier in the course to be methods, and modify the main function to accept these methods.
Methods SolutionBrenna live codes the solution to the exercise.
InterfacesBrenna defines what an interface is, namely a list of methods that describes the behavior of types that implement it.
Refactor for an InterfaceBrenna live codes a describer interface, and adds a method that takes in any type that satisfies the describer interface.
Empty InterfacesBrenna defines what an empty interface is, what type of values it can hold, and explains how the empty interface can be useful.
Web Servers & RoutesBrenna begins building a todo app using Go. Through a code-along exercise, students are shown how to spin up a basic web server and handle routes.
Go TemplatesBrenna creates another endpoint for the todo application, and uses Go templates to generate HTML output on a webpage. How to send the appropriate server error to the webpage when a template cannot be parsed is also covered.
Template Errors & DataBrenna gives a brief introduction to what the go template is doing, then demonstrates what an error would look like if the template cannot be parsed by the application. How to pass data into the template to be rendered when the template is executed is then live-coded into the application.
Submitting a FormBrenna uses the http package to parse the data submitted to the todo application form, and summarizes the goals as well as the limitations of the application.
Hitting an External API
External APIsBrenna introduces the section on getting data from an external API by visiting the website for the Star Wars API, the API that will be used for the rest of this section. After hitting one of the API endpoints on the site, students are instructed to create a basic route.
Making an HTTP RequestBrenna demonstrates how to access the Star Wars API by live coding a function to make a GET request to the API endpoint.
Parsing an HTTP ResponseBrenna demonstrates how to use json.Unmarshal to parse JSON-encoded data from an HTTP response and store the received data into Go structs.
Getting Nested JSON DataBrenna uses the data from the HTTP response to make additional GET requests to the API, gathering information about planets for each returned person.
Concurrency Definition & PracticeBrenna explains what a Goroutine is, how to implement it, and live codes an example of concurrency using the sync package.