liveBook · Manning

Package

As explained in Go in Practice, Second Edition

A Go package is a compilable unit of related Go source files whose exported identifiers are referenced through the package name.

A Go package is a compilable unit of related source files. Import a package by name and reference its available identifiers with that name as a prefix, such as fmt.Println. section 1.2.4

Use packages through the Go toolchain:

  • Group imports in parentheses and keep them alphabetized; go fmt can maintain this formatting. section 1.2.4
  • Import standard-library packages such as fmt and net/http alongside external packages identified by module or URL paths. section 1.2.4
  • Use go mod for dependency management and go get ./... to obtain package dependencies. section 1.2.4
Listing 1.9 Single package import
package main

import "fmt"         #1

func main() {
    fmt.Println("Hello World!")       #2
}

A minimal main package imports fmt and calls fmt.Println, showing package-qualified use in a runnable program. section 1.2.4

How Go in Practice, Second Edition covers it

How deep it goes
Explains imports, naming, grouping, external paths, and formatting conventions through standard-library and external examples.
Examples
Uses fmt.Println, grouped fmt/net/http imports, an external golang.org/x/net/html path, and go get ./....
What it assumes
Assumes basic Go program structure and introduces package use through standard-library examples.
What you can do after
Apply it via Go imports to call standard-library and external package functionality from a program.
How it connects
Connects packages with namespaces, Go modules, dependency management, go fmt, and the standard library.

Also explained in

Compare how 7 books explain package →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.