go package details

A package is a unit composed of go language programs, which can refer to itself or the contents of other packages. There are many .go files under a package, and each .go file belongs to only one package. The file name can be unique with the package name, similar to Python.
Import a package with the keyword " import "
import "fmt"
import "io"

or:
import (
	"fmt"
	"io"
)


package alias:
import (
	ft "fmt"
)

func main() {
	ft.Println("Hello World!")
}


Note:

1. Aliases and original names cannot be used at the same time
import (
	ft "fmt"
)

func main() {
	fmt.Println("Hello World!")
}


If you use it, it will report an error:

2. If the package is introduced, it will report an error if it is not used (vscode will check it when saving)
imported and not used: "io"

This error is to refer to io, but it is not used
. 3. When importing a package, you can only refer to variables, constants, functions, structures, etc. in the package that begin with capital letters. The beginning of the lowercase letter in the package can only be used in the package, similar to the (private) field

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992612&siteId=291194637