import a package with an alias in go

To import a package with an alias in go, you can use the import keyword followed by the package path and the desired alias after the as keyword. Here is an example:

main.go
import (
    fmtAlias "fmt"
)

func main() {
    fmtAlias.Println("Hello, World!")
}
85 chars
8 lines

In this example, we have aliased the fmt package as fmtAlias. We can now access all the exported functions and variables of the package using the alias fmtAlias.

Note that the package name used in the code should match the alias used in the import statement.

related categories

gistlibby LogSnag