General structure of Go program:
- Go programs are organized through the package (similar to Python)
- Only packages with a package name called Main can contain the main function
- One executable program has and only one Mian package
- Importing Other non-main packages with the Import keyword
- Constants are defined by the const keyword
- Declaring and assigning global variables by using the var keyword outside the body of the function
- Declaration of a struct (struct) or interface (interface) using the type keyword
- Declaring a function with the func keyword
Basic components of the Go language
- Package Declaration
- Introduction Package
- Function
- Variable
- Statements & Expressions
- Comments
Format of Go Import package
--After importing the package, you can use the format <PackageName>.<FuncName> to call the functions in the package;
--If a function or type that is not called after the package is imported will report a compilation error
Package aliases
-When a third-party package is used, the package name may be very close or identical, and the alias can be used to differentiate and invoke
Omit call
- not recommended to use , easy to confuse
- cannot be used with aliases at the same time
Visibility stocks
In the-go language, the case is used to determine whether the constant, variable, type, interface, struct, or function can be called by an external package.
By convention, the first letter of the function name is private, and the first letter of The function name is public
192 Reads