import declaration
The line near the top of a Go file that names the packages the file uses, such as import "fmt".
In more detail
Several imports can be grouped in parentheses. Importing a package you never use is a compile error, not a warning, which keeps files honest. The name you call the package by is the last part of its import path.
Example
import (
"fmt"
"os"
)Related terms
- import path — The string that identifies a package in an import line: the module path followed by the folder inside the module.
- Go package — A folder of Go source files that are compiled together and share one package name, which other code imports as a unit.
- import cycle — A situation where two or more packages import each other, directly or in a loop, which the Go compiler refuses to build.
- Go standard library — The set of packages that ships with Go itself, such as fmt, os, io, net/http, encoding/json and testing.
Taught in
- What Go Is and Why It Matters — Concurrent Systems Programming with Go
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Go Workspaces and Modules — Concurrent Systems Programming with Go
- Your First Program and go run — Concurrent Systems Programming with Go
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Pointers and Memory — Concurrent Systems Programming with Go
- Arrays, Slices, and Maps — Concurrent Systems Programming with Go
- Structs and Methods — Concurrent Systems Programming with Go