Go programs are organized through the package (similar to the Python library)
Only packages with a package name called Main can contain the main function (and the main function is also the entry for a program)
One executable program has and only one main package
Importing other non-main packages via 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----general (custom) type
Declaring a function with the func keyword
The General format is:
Packages main//current package name, only the package name is main, you can generate the executable file import "FMT"//Introduce a package import ("FMT" "OS")//here with parentheses, you can introduce more than one package at a time, of course, you can import each Times to introduce one. (The introduction does not use, the compile time will be error) const PS = 3.14//const used to define a constant var name = "Lixin"//var used to define a variable, is generally the declaration and assignment of a global variable type Newtype int//type with To declare a type, followed by an int, representing the general type of declaration of type Gopher struct{}//followed by a struct representation is a struct type, and of course there are some parameter definitions, omitted here so with {}type Golang interface{}// Represents the declaration of an interface, Func main () {//by the main function as the starting point of the program FMT. Println ("Hello World")//Call the PRINTLN function of the FMT package to output the string}
Tips for referencing:
Import "FMT" Here I can alias the imported package to set the import test "FMT" then I call FMT below. The println function is: test.println We can also make an ellipsis call--Generally not!! Import. "FMT" before the addition of a dot to indicate the omitted call, then call the module inside the function, you can not write the module name of import. "FMT" Func Main () {Println ("Hello,world")}
This article is from the "Your Night" blog, be sure to keep this source http://lixin15.blog.51cto.com/3845983/1846826
Golang Study notes (1)---Go program general structure