直接导包
import (
"fmt"
)
导过包后就可以使用包里的函数了,比如
fmt.Println(“hello world”)
用 . 的方式导包
import(
. "fmt"
)
这种导包方式可以让使用该包函数时省略包名
Println(“hello world”)
使用别名的方式导包
import(
f "fmt"
)
就是给包起了个别名,调用包里函数时可以使用别名调取
f.Println(“hello world”)
使用 _ 的方式导包
import(
_ "github.com/go-sql-driver/mysql"
)
这种导包方式不直接调用包里的函数,而是调用该包里的 init 函数。