Advanced Go Training
Advanced Go Training was designed with the experienced developer in mind. It assumes that you have already learned the day to day Go concepts, and are ready to master concepts such as Concurrency and advanced testing methodologies. It finishes with a comprehensive tour of the pprof tool and how to profile your Go code and determine how to make it more performant.
Length3 days (with an optional 4th day). Each day is 4 hours long including a 15 minute break.
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.
- You have been doing daily Go development for 3-6 months and want to master more advanced topics.
- You are looking to learn advanced concurrency patterns.
- You want to learn more advanced Go testing patterns, such as asynchronous testing, mocking, stubbing, etc.
- You want to learn how to profile your Go code and improve performance.
- 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 3 to 6 months of daily Go experience.
- 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.
- Install and configure an editor for Go.
- Have a functioning Go environment installed with Go 1.13 or later.
- Sign up for a Github account if you don't already have one.
- Install GraphViz (needed for generating Go profiles).
Suggested Followup Learning
- Students will be able understand and create advanced concurrent Go patterns.
- Students will understand how to create tests for asynchronous (concurrent) code.
- Students will be able to stub out Go structures for better unit testing.
- Students will understand the Go test ecosystem, as well as how to configure and run their Go tests efficiently.
- Students will be able to profile and improve performance of Go code.
This chapter covers general information about your instructor and course materials.
Understanding the different options to run tests can greatly reduce the feedback cycle during development. In this chapter, we will cover:
- Running Specific Tests
- Verbose Output
- Failing Fast
- Parallel Options
- Short Testing
- Timing Out Tests
- Race Conditions
Code coverage is a great tool to show what part of your code is being tested. It will help identify areas that need more testing, as well as assist in making sure your tests actually test the part of the code you think it does.
No project is complete without great documentation. Example tests are a great way to not only document your code, but ensure that the examples you use always work as they are actually a test in addition to the documentation.
Stubbing & Mocking Tests
It's easy to decouple packages in Go using interfaces. Because of this, testing can also be much easier. However, you typically want to stub out your interfaces in tests so that unit testing is much easier. This chapter will cover how to write a stub for a service to enable easy and precise testing.
In the standard library there are two mechanisms for us to use to test web applications.
- Unit Style Testing
- Integration Style Testing
These are not their "official" names, but we believe they do a good job of describing the styles of testing. In this chapter, we will cover both styles of testing and how to use them.
Testing Asynchronous Tasks
Many times you may be testing parts of your code that have service dependency that run for an unknown amount of time.
Examples of these may be task queues, distributed system calls, etc.
Because you don't know how long they may take to execute, testing them can present some challenges.
In this chapter we will learn how to set up tests both effectively and efficiently for testing async processes.
Note: This chapter assumes the audience is familiar with concepts such as
- httptest package
- concurrency primitives such as channels and goroutines
There are many tools to assist with testing. This chapter will cover the following topics:
- Comparing complex structures with
- How to use the
- Fuzzing your API
Workflow automation can significantly improve developer productivity. This chapter will show how to implement some very simple, lightweight automation to automatically run tests and coverage.
Testing With IO
Many times the software we design relies on reading and writing data, either to disk, network connections, etc. This chapter will show you how to properly architect your software so that it is easily testable without the need to create temporary files
as well as show how to use the
io interfaces in your tests.
Go comes with a powerful set of tools for profiling and improving the performance of your code. Benchmarking is one of those tools, and the first one most developers start with. In this chapter we will cover basic benchmarking, some common benchmarking mistakes, and how to compare benchmarks to see if performance has improved.
Go ships with a number of profiling tools. This chapter will walk you through how to:
- Use interactive
pprofwith a cpu profile
- Use interactive
pprofwith different types of memory profiles
- Generate profiles from benchmarks
- Generate profiles from live/running applications
- Generate torch graphs from benchmarks or live/running applications
Optimizing Go Services
Understanding how to use tools like
pprof and writing benchmarks is important, but understanding common coding pitfalls and how to spot them with those tools is the end goal.
In this interactive workshop, you will:
- Learn several compiler tricks to spot areas for improvement
- Learn how to properly buffer readers and writers
- Find and remove unnecessary memory allocations
- Use flame graphs to identify redundant calls
The execution trace captures a wide range of execution events such as goroutine creation/blocking/unblocking, syscall enter/exit/block, GC-related events, changes of heap size, processor start/stop, etc. A precise nanosecond-precision timestamp and
a stack trace is captured for most events. The generated trace can be interpreted using
go tool trace.
This chapter will walk through how to enable tracing, use the trace tool, and spot performance issues.
This chapter covers where to get more support on Go, recommends books and videos, and list the contact information for our instructors.
Concurrent programming in many environments is made difficult by the subtleties required to implement correct access to shared variables. Go encourages a different approach in which shared values are passed around on channels and, in fact, never actively shared by separate threads of execution.
This chapter will cover concurrency as it pertains to Go, what goroutines are, as well as a basic overview of the scheduler and terminology used.
Concurrency With The Sync Package
This chapter covers goroutines and how to synchronize communication between them. Mechanics for synchronization such as
Mutexes are explored along with the corresponding patterns for each. Additionallywe will
cover how to spot common concurrency bugs and tools used to debug them.
Concurrency With Channels
Channels are a conduit in Go used to communicate between goroutines. This chapter covers basic channel usage along with the corresponding patterns for each. Find out the difference between a buffered and unbuffered channel, and when to use them. Also discover how to use channels for signaling for concepts such as graceful application shutdown. Finally, learn how to spot common concurrency pitfalls and how to properly structure your concurrent code for to avoid them.
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes. Context is used for controlling concurrent subsystems in your application. This chapter will cover the different kinds of behavior with contexts including canceling, timeouts, and values.
Testing in Go is easy, and simple to use. There is a strong emphasis on testing in Go. The compiler will catch a lot of bugs for you, but it can not ensure your business logic is sound or bug-free.
While the testing package isn't large, there are some features that are not properly understood. In this chapter we will cover the following concepts:
- Error vs. Fatal
- Failure Messages
- Testing Packages
Table Driven Testing
Table driven tests can be used to cover a lot of ground quickly while re-using common setup and comparison code. Table driven testing is not unique to Go, however, it is very powerful. In this chapter we will cover the different ways to create, run, and isolate table driven tests.
Interfaces in Go provide a way to specify the behavior of an object:
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
pointer receivers and how they affect the ability to satisfy an interface.
Embedding And Composition
Go does not provide the typical type-driven notion of subclassing. However, it does have the ability to “borrow” pieces of an implementation by embedding types within a
interface. This chapter will cover how promotion
from embedding works as well how collision and overriding are handled. We will also walk through how to embed types to be able to satisfy a specific interface.
Error handling in Go can feel a bit tedious at first. However, this chapter will cover the benefits of how Go's error model results in more reliable code. This chapter will also cover how to handle basic errors and return errors as an interface that satisfies the error type. Concepts such as custom error types, panics, recovering from panics, and sentinel errors are also covered.