This is a creation in Article, where the information may have evolved or changed.
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:
The package listens to main listen//current pack name, only the package name is main, can generate executable file import listen to "FMT" listen to hear//introduce a package import listen ("FMT" "OS" Listen listen) listen to hear//here with parentheses, you can introduce more than one package at a time, Of course, you can import one at a time. (The introduction does not use, the compile time will be error) Const LISTEN PS Listen = listen to 3.14 listen//const used to define a constant Var listen to the name listen = Listen to "Lixin" listen to//var to define a variable, Generally the declaration and assignment of a global variable type listen Newtype Listen int listen to the//type used to declare a type, followed by an int that represents a generic type of declaration type listen gopher listen to struct{} listen//The struct representation behind is a struct type, Of course there are some parameter definitions, omitted here so use {}type listen to Golang listen to interface{} Listen//expression is an interface declaration func listen main listen to listen to hear//by the main function as the starting point of the program listen to listen to the FMT. Println ("Hello Listening World")//Call the PRINTLN function of the FMT package to output the string}
Tips for referencing:
Import Listen to "FMT" listen here I can alias the imported package import listen to test listen to "FMT" then I call FMT below. Println the function of the time is: test.println We can also make the omission of the call listen---Generally not use!! Import Listen. Listen to the "FMT" to listen to the previous add point means omit the call, then call the module inside the function, you can not write the module name of the import listen. Listen to "FMT" Func listen to main listen () {Println ("Hello,world")}
This article is from the "Your Night" blog, be sure to keep this source http://lixin15.blog.51cto.com/3845983/1846826