There are two types of imports available in Go. In both cases, we generate the same reference to the package itself. This is done by creating an importMoniker. This import moniker
import "fmt"
// ^^^------ reference github.com/golang/go/std/fmt
import f "fmt"
// ^--------- local definition
// ^^^---- reference github.com/golang/go/std/fmt
// Special Case, "." generates no local def
import . "fmt"
// no local def
// ^^^---- reference github.com/golang/go/std/fmt
So given this kind of import, you will see the following.
import (
"fmt"
. "net/http"
s "sort"
)
- Regular
"fmt"
import. Creates only a reference to the moniker
- Named
s "sort"
import. Creates both a reference and a definition. Any local references tos
in this case will link back to the definition of this import."sort"
will still link to the external package.
.
import. This will also only create a reference, because.
does not create a new definition. It just pulls it into scope.