Chapter 3. Packaging and tooling

 

In this chapter

  • Understanding how Go code is organized
  • Using the Go command
  • Going farther with other Go developer tools
  • Collaborating with other Go developers

In chapter 2 you got an overview of the syntax and language structure of Go. Now you’ll dive deeper into how code is organized into packages and how you interact with those packages. Packages are a critical concept in Go. The idea is to separate semantic units of functionality into different packages. When you do this, you enable code reuse and control the use of the data inside each package.

Before we get into the particulars, you should already be familiar with the command prompt or system shell, and you should have Go installed according to the guidelines in the preface of this book. If you’re ready, let’s start by understanding what a package is and why it’s important in the Go ecosystem.

3.1. Packages

All Go programs are organized into groups of files called packages, so that code has the ability to be included into other projects as smaller reusable pieces. Let’s look at the packages that make up Go’s http functionality in the standard library:

net/http/
    cgi/
    cookiejar/
        testdata/
    fcgi/
    httptest/
    httputil/
    pprof/
    testdata/

3.2. Imports

3.3. init

3.4. Using Go tools

3.5. Going farther with Go developer tools

3.6. Collaborating with other Go developers

3.7. Dependency management

3.8. Summary