How to introduce packages in Go language: You can directly use [import "package name"] to introduce a package. If you need to import multiple packages at the same time, you can use [import {"package name" "package name" "package name"}] to import them.
#The operating environment of this article: windows10 system, GO 1.11.2, thinkpad t480 computer.
(Learning video sharing: Programming teaching)
Specific method:
The first is the simplest way to import packages, which is to use import directly "fmt" to import an fmt package
If you want to import multiple packages at the same time, you can write like this
Of course, you can also use the following method for importing multiple packages. However, the following writing format will be automatically formatted in the second way when gofmt is used.
The most commonly used way of writing imported package modules is as follows
Sometimes the package we import is in the secondary directory, then you can write like this
import "net/http" imports the http module in the net directory
Of course, GO language supports direct import of an online module. For example, the third-party package module is on github; we can directly use import "url" to import it without downloading and installing it
In fact, the functional principle of online importing package module is as follows . The GO compiler will automatically download the package file in the URL to the local GOPATH directory you set. The directory format is the directory path of the URL, and then perform the import operation. We can combine the above import methods, as shown below
Related recommendations:golang tutorial
The above is the detailed content of How to introduce packages in go language. For more information, please follow other related articles on the PHP Chinese website!