1 Go language structure
" FMT " Func Main () { /**/ FMT. Println ("Hello, world! " )}
The basic components of the Go language are the following sections:
- Package declaration: Defines the package name, the first line of the non-comment in the source file must indicate which package the file belongs to, and packagesmain represents a program that can be executed independently , and each Go application has a a package named Main.
- Introduction Package: The FMT package implements the format IO (input/output) function.
- Function: The main function is what each executable program must contain , generally the first function executed after startup (if there is an init () function, the function is executed first ).
- Variables: When identifiers (including constants, variables, types, function names, structure fields, and so on) start with an uppercase letter , such as: Group1, then an object with this form of identifier can be used by the code of the external package (the client program needs to import the package first), This is known as an export (like public in an object-oriented language); identifiers that start with lowercase letters are invisible to the outside of the package, but they are visible and available within the entire package (like protected in object-oriented languages) )
- Statements & Expressions:
- Note: single-line comment//, multiline comment/**/
The structure of the Go language in Lesson two