import a package in go

To import a package in go, use the import keyword followed by the package path. For example, to import the fmt package:

main.go
import "fmt"
13 chars
2 lines

You can also import multiple packages by separating them with commas:

main.go
import (
    "fmt"
    "math/rand"
)
37 chars
5 lines

It's common practice to import packages in the format import "github.com/username/package" to import packages from external sources.

related categories

gistlibby LogSnag