"Go language combat" study notes - package


Chapter 3 Packaging and Toolchains


Packages are a very important concept in Go. The design philosophy is to use packages to encapsulate the functionality of different semantic units. Doing this allows for better code reuse and better control over the use of data within each package.

3.1 Package


All Go programs are organized into groups of files, each group of files is called a package . In this way, the code of each package can be used as a small reuse unit and be referenced by other projects.

3.1.1 Package name conventions


When naming packages and their directories, you should use concise, clear, and all-lowercase names , which facilitates frequent typing of package names during development.

3.1.2 main package


In Go, a package named main has a special meaning . The Go compiler will attempt to compile a package with this name into a binary executable. The word command
is often used in Go documentation to refer to an executable program.

 If the package name is changed to a name other than main, such as hello, the compiler will consider this just a package,
 not a command.

 

Get package documentation: You can visit http://golang.org/pkg/fmt/ or type godoc fmt in the terminal to learn more
about the fmt package.

Guess you like

Origin blog.csdn.net/wangchao701123/article/details/123136006