Home > Article > Backend Development > About Golang-import import package syntax
The following tutorial column will introduce you to the Golang-import import package syntax. I hope it will be helpful to friends who need it!
import ( "fmt")Then in The code can be called in the following ways:
fmt.Println("hello world")
The fmt above is the standard library of the Go language. It actually goes to GOROOT to load the module. Of course, Go's import also supports the following two methods to load the modules written by yourself. Module:
//1.相对路径//当前文件同一目录的model目录,但是不建议这种方式importimport "./model"
//2.绝对路径//加载GOPATH/src/shorturl/model模块//简单理解就是:项目名/包名import "shorturl/model"
Special import syntax for package
import ( . "fmt")
Alias operation
import ( f "fmt")
_Operation
import ( "database/sql" _ "github.com/ziutek/mymysql/godrv")
to reference the package. Even if you use _operation to reference a package, you cannot call the exported function in the package through the package name, but just to simply call its init function ().
The above is the detailed content of About Golang-import import package syntax. For more information, please follow other related articles on the PHP Chinese website!