Introduction to Go Training
Intro to Go (golang) is designed to get existing software teams with little to no Go experience ready to write production ready code. It focuses on the common mistakes that developers new to Go are likely to make, and ensures that they have practical knowledge to be productive in their day to day efforts.
Length
5 days. Each day is 4 hours long including a 15 minute break.Class Size
Our classes are priced for small and large classes. We offer classes starting at only five students, up to 100 students. We recognize that each company has specific needs and budgets.
For pricing, fill out our contact us form and you'll receive an automated reply with our current rates.
Target Audience
- You have little to no Go experience.
- You have a current or upcoming project that will be written in Go.
Prerequisites
- Familiarity and comfort navigating and basic file manipulation at the command line.
- Familiarity and comfort with a modern code editor, including creating and modifying files and projects.
- You have at least 6 months of experience with other modern development languages such as Java, C#, Swift, JavaScript, Python, Rust, etc.
- Familiarity with basic programming concepts and structures such as variables, loops, conditionals, etc.
- Computers should be capable of modern software development, such as access to install and run binaries, install a code editor, etc. Full instructions referenced here: preparing your environment for Go development. It may be necessary for them to have root/admin access to their computer.
Recommended Preparation
- Install and configure an editor for Go.
- Sign up for a Github account if you don't already have one.
Suggested Followup Learning
- Testing, Stubbing, and Automating Go Work Environments
- Advanced Go Development
- Web API Development in Go
Expected Outcomes
- Students will be able read and understand Go syntax.
- Students will be able to spot common coding pitfalls in Go and correct them.
- Students will understand the internals of Slices and how to use them properly.
- Students will understand how to write idiomatic Go using core principles such as embedding and interfaces.
- Students will have a strong understanding of concurrency and how to apply it to their projects.
- Students will understand how to create proper tests, including table tests.
Course Details
Day One
Go Language Essentials: Building Blocks of Effective Code
In this chapter, we will explore the essential components of the Go programming language. You will learn how to use the keywords, operators, and delimiters that form the foundation of Go, along with the idiomatic ways to structure your code. We will also delve into data structures, including how Go handles default values (zero values) and the characteristics of structs. This chapter covers Go’s treatment of strings, UTF-8 encoding, and the different types of string literals. Finally, we will examine how to declare variables and constants, and introduce the use of the iota keyword for efficiently handling constant definitions. This chapter sets the stage for mastering Go by equipping you with the knowledge of its core language features.
Modern Go Development Workflow
Modern Go development requires more than just writing code. This chapter covers essential tools and practices for professional Go development including hot reload with air, goroutine leak detection with goleak, build tags, build info embedding, and IDE integration. These tools significantly improve development velocity and code quality. By the end of this module, you will be able to: * Set up hot reload for rapid development iteration * Detect and prevent goroutine leaks * Use build tags to control compilation
Break
Tea/Coffee Break.
Mastering Arrays and Iteration in Go: Exploring arrays, loops, and common iteration patterns
This chapter provides an in-depth exploration of arrays and iteration in Go. You will learn the fundamentals of arrays, including their fixed size and type, how to create and initialize them, and how Go handles array indexing. The chapter also covers common loop constructs, including `for` loops, `range` loops, and control mechanisms like `continue` and `break`. You'll also gain hands-on experience with two-dimensional arrays, iteration patterns, and using Go’s `range` keyword to simplify array iteration. By the end, you'll have a solid foundation for working with arrays and iteration in Go, setting the stage for more advanced data structures.
Mastering Slices for Dynamic Data Structures: A deep dive into slice manipulation and memory efficiency
This chapter takes an in-depth look at slices in Go, a powerful tool for working with dynamic data structures. You'll start by understanding the basics of slice creation, initialization, and iteration. Then, you'll explore advanced techniques for growing, shrinking, and manipulating slices without unnecessary memory allocation. Key topics include the `append` function, slice internals, and memory management techniques like copying and deleting from slices. Additionally, you will learn about Go's slices package, which provides enhanced tools for sorting, searching, and managing slices efficiently. You'll also explore the iterator functions introduced in Go 1.23, enabling powerful slice transformations and batch processing. By mastering slices, you'll be able to work more effectively with Go's dynamic data structures.
Day Two
Working with Maps for Key-Value Storage: Utilizing maps for dynamic collections and efficient data access
This chapter delves into Go’s powerful map data structure, a flexible key-value storage system essential for dynamic collections and efficient data retrieval. You’ll learn the fundamentals of map creation, initialization, and iteration, as well as techniques for updating, deleting, and checking the existence of values. With hands-on exercises, you’ll explore how to handle map errors, avoid common pitfalls, and manipulate complex data types stored in maps. By mastering Go maps, you will efficiently manage dynamic collections and improve your data access strategies.
Pointers and Memory Management in Go: How pointers work in Go and their role in efficient memory usage
This chapter introduces pointers in Go, demystifying their role in memory management and efficient data handling. You’ll learn the difference between passing by value and passing by reference, how to declare and use pointers, and when to leverage pointers for better performance and flexibility. The chapter will also explore the security implications of pointers, the basics of pointer dereferencing, and how Go’s memory management techniques avoid common pitfalls seen in other languages. Through practical examples and exercises, you will gain a deeper understanding of when and how to use pointers effectively in Go.
Break
Tea/Coffee Break.
Defining and Using Functions in Go: Creating reusable functions, including variadic functions and closures
This chapter explores the fundamentals of functions in Go, guiding you through creating reusable functions with multiple arguments and return values. You will learn how to define variadic functions that can handle a dynamic number of arguments, utilize closures to capture external variables, and understand methods for attaching functions to types. Additionally, the chapter delves into advanced concepts like deferred function calls, error handling, function types, and the use of `init` functions to perform pre-execution setup. Through practical examples, you'll build the skills needed to create flexible, efficient Go functions.
Day Three
Interfaces and Polymorphism in Go: Understanding Go's approach to interfaces and dynamic behavior in type systems
Interfaces in Go provide a way to specify the behavior of an object: `If something can do this, then it can be used here`. This chapter will take a look at how to use interfaces to abstract that behavior. Concepts such as the `Empty Interface`, satisfying multiple interfaces, and asserting for behavior will be covered. Additionally, this chapter will cover the difference between `value` and `pointer` receivers and how they affect the ability to satisfy an interface. > The larger the interface, the weaker the abstraction. -- Rob Pike
Break
Tea/Coffee Break.
Embedding and Composition for Code Reuse: Using Go’s embedding feature for cleaner, more modular code
This chapter delves into Go's powerful embedding and composition mechanisms, which allow developers to build cleaner, modular, and reusable code without traditional inheritance. Instead of subclassing, Go enables embedding types within structs and interfaces, promoting fields and methods automatically. You will explore how embedding works, how method promotion simplifies code, and how to handle collisions and method overriding effectively. This chapter also covers how embedding can be used to satisfy interfaces, making your code more versatile and maintainable through practical examples.
Day Four
Error Handling and Best Practices (Dealing with errors, panics, recover)
Go's approach to error handling is simple but powerful, emphasizing clear control flow over error-prone constructs like `try/catch`. In this chapter, you will learn how to effectively manage errors in Go using idiomatic patterns. The chapter covers basic error handling, creating and returning errors, and best practices such as wrapping errors for better context. You will also explore advanced topics like custom error types, sentinel errors, error chain traversal, modern error inspection with `errors.Is()` and `errors.As()`, custom unmarshal error handling, and the use of Go's `panic` and `recover` for managing unexpected failures. By the end, you'll have a deep understanding of how Go's error model leads to more reliable and maintainable code, while learning when and how to use recovery mechanisms for graceful error handling.
Logging
In Go (golang) release 1.21, the [slog](https://pkg.go.dev/slog) package will be added to the standard library. It includes many useful features such as structured logging as well as level logging. In this article, we will talk about the history of logging in Go, the challenges faced, and how the new `slog` package will help address those challenges. In this chapter, we'll cover the following topics: - Introduce the Slog package that is released in Go 1.21 - Cover the major features being introduced with this logging package
Break
Tea/Coffee Break.
Concurrency Fundamentals in Go: Understanding Go's approach to concurrency with goroutines
This chapter introduces Go's unique approach to concurrency, focusing on goroutines as lightweight, independent functions that enable efficient concurrent programming. You will explore how Go's concurrency model encourages communication through channels rather than shared memory, making code faster, more robust, and easier to scale. The chapter also covers the differences between concurrency and parallelism, the role of Go's scheduler, and how channels simplify communication between goroutines. Additionally, you’ll get a glimpse into the potential pitfalls of data races and Go’s powerful race detector.
Leveraging the Sync Package for Concurrency Control: Utilizing the sync package to handle complex synchronization problems
In this chapter, we will explore how Go's `sync` package provides powerful tools to manage synchronization between goroutines, ensuring safe access to shared memory. You will learn how to utilize synchronization primitives like `WaitGroups`, `Mutexes`, `RWMutexes`, `sync.Once`, `sync.Cond`, and `Semaphores` to coordinate concurrent operations effectively. Additionally, we will cover common concurrency issues such as race conditions, deadlocks, and bugs, and demonstrate how to detect and fix them using Go's race detector and other tools. We will also explore advanced patterns including one-time initialization, condition variables, and controlling concurrency with semaphores, comparing different approaches for throttling concurrent operations. This chapter will equip you with the knowledge to handle complex concurrency problems, making your Go programs more robust and efficient.
Day Five
Concurrency With Channels: Safe Communication Between Goroutines
This chapter delves into Go's powerful concurrency mechanism using channels to enable safe communication between goroutines. You will learn how to implement basic and advanced channel usage, including buffered and unbuffered channels, how to signal completion, and gracefully shut down applications. The chapter will guide you through practical examples and best practices for avoiding common concurrency pitfalls, making it easier to build robust, concurrent applications that scale efficiently. Channels are a typed conduit through which you can send and receive values.
Break
Tea/Coffee Break.
Understanding the Context Package: Managing request-scoped data, deadlines, and cancellation with the context package
The `context` package in Go is essential for managing request-scoped data, timeouts, and cancellations across various parts of your application. This chapter provides an in-depth look into how Go's context package helps simplify managing concurrent operations. You'll learn how to propagate values like user data across goroutines, handle timeouts to ensure efficient resource management, and gracefully cancel operations when required. By the end, you’ll understand how to avoid common pitfalls and implement the `context` package to build robust, scalable Go applications.
Optional (time permitting)
Testing Basics: Writing and Running Unit Tests
This chapter introduces the fundamentals of testing in Go, with a focus on writing and running unit tests using the built-in `testing` package. You'll learn how to structure tests, the importance of naming conventions, and how to utilize the `*testing.T` type to create effective test cases. Key concepts such as the difference between `Error` and `Fatal`, crafting meaningful failure messages, and organizing internal vs. external tests are explored. Additionally, we'll cover useful helper functions, alternative testing packages, and provide practical examples to help you develop reliable, maintainable tests for your Go applications.
Table-Driven Testing for Flexible and Scalable Tests
Table-driven testing is a powerful and efficient way to create clean, reusable, and scalable tests in Go. By defining test cases as data in tables, you can minimize duplication and easily extend test coverage by adding new cases. This chapter covers how to implement table-driven tests, demonstrating how to isolate test logic, reduce redundancy, and ensure your tests remain organized. You will also learn advanced techniques like running sub-tests, parallelizing table-driven tests, and handling setup and teardown logic for enhanced performance and clarity
Managing Modules and Packages in Go: Organizing and Scaling Large Applications
This chapter provides an in-depth guide on managing Go modules and packages to support the scalability of large applications. You'll explore best practices for organizing Go codebases using packages, learn about Go's module system for dependency management, and understand how to troubleshoot package dependencies effectively. The chapter covers: - **Go Packages:** An introduction to Go’s package structure, naming conventions, and best practices for organizing code in packages for maintainability and clarity. It explains the significance of capitalization for scope and visibility and touches on security considerations when exposing or hiding variables and types.
Building And Compiling Go Applications
In this chapter, we dive into the mechanics of building and compiling Go applications. Go’s ability to produce efficient, statically linked binaries across multiple platforms makes it an excellent choice for various deployment environments. You will learn how to use the `go build` and `go install` commands to compile your Go code into standalone executables. We will also explore how to embed build metadata like version numbers and commit SHA-1 hashes into binaries using linker flags. Additionally, the chapter covers build tags, a powerful feature that enables platform-specific compilation and fine-grained control over how your code is built. By the end of this chapter, you will be well-equipped to compile Go applications for both development and production, with support for cross-platform distribution.
Tooling
Go ships with a strong suite of built-in tools. This chapter will go over the most common tools and how to use them in your daily development workflow. In addition to the tools that ship with Go, there are a set of very important linters and vetters that can catch runtime bugs as well as significantly improve code quality and performance. This chapter shows what those tools are and how to use them. * Lot of built in and third party tools * Some are so amazing they should be automated in your development process or even your IDE