Each Go program is made up of some packages.
Original address: Https://golang-book.readthedocs.io
Welcome to our public number: Appetizer programming (Coding-fan)
The program main starts execution from the package.
package mainimport ( "fmt" "math/rand")func main() { fmt.Println("My favorite number is", rand.Intn(10))}
In this program, import two packages via import, fmt and math/rand (package path).
By convention, the package name is the same as the last part of the package path. For example, math/rand the source files in the package package rand begin with a statement.
Import statement
Go introduces the package through the import statement and is used in the code.
importThere are two different ways to write a statement, and the above example is one of them- bulk import ; the second is divided into multiple statements:
import "fmt"import "math"
Although there is no real difference between the two styles, it is recommended to use bulk notation , which is the best style .
Name Export
In the Go language, names beginning with uppercase letters are exported ( exported ). An example Pizza is an export name, which math is also in the package Pi .
package main import ( "fmt" "math" ) func main() { fmt.Println(math.Pi) }
Instead, pizza and pi because it is not capitalized, it is not exported.
After a package is imported, it can only be referenced to the exported name. Any other non-exported name outside the package is not accessible (not visible).
Next
In the next section, let's take a look at the Go language function.
Subscribe to the update For more information, please follow our public number:
Vegetable Learning Programming