Importing packages

suggest change

Import packages by their package paths:

import "example.com/project/package1"

Group multiple imports together:

import (
    "fmt"
    "example.com/project/package1"
    "example.com/project/package2"
)

For packages in the same module, use a path beginning with the module path declared in go.mod. Relative imports such as ./package1 are not supported in module mode.

The imported package name is usually the final path element. An explicit alias resolves name collisions:

import (
    "fmt"
    textfmt "example.com/project/fmt"
)

A dot import places exported identifiers in the importing file's scope, but it obscures where names come from and should generally be avoided:

import . "fmt"

A blank import runs a package's initialization for its side effects without binding its exported identifiers:

import _ "example.com/database/driver"

Go reports unused ordinary imports as compile errors.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents