Skip to content

Importing

Use import to bring other packages into scope. You can import single packages, multiple packages in a block, rename imports with aliases, or use a blank import (_) for side effects (e.g., registering a driver).

Show different import styles.

package main
import (
"fmt"
"math/rand"
myfmt "mylib/fmt" // alias
_ "image/png" // blank import for side effect
)
func main() {
fmt.Println(rand.Intn(100))
myfmt.Println("Hello")
}
Terminal window
42
Hello