Learn from here
Https://golangcaff.com/docs/build-web-application-with-golang
25 keywords for 1.GO
Break default Func interface Selectcase
Defer go map struct chan else goto package
Switchconst Fallthrough If range typecontinue
For import return Var
Configuring the Environment
To define a variable rule:
Using the var keyword is the basic way to define variables for go, unlike the C language, where go puts the variable type behind the variable name:
Define a variable named "VariableName" with the type "types"
var variableName type
Define multiple variables
Defines three types that are "type" variables
var name1 name2 Name3 Type
Defining variables and initializing values
var name1 type = value
Simultaneous initialization of multiple variables
/*
Defines three types that are "type" variables and are initialized to the corresponding values respectively
Vname1 for V1,vname2 to V2,vname3 for v3
*/
var vname1,vname2 vname3 type = V1,v2,v3
/*
Define three variables that are initialized to their respective values
Vname1 for V1,vname2 to V2,vname3 for v3
Then go will help you initialize them based on the type of their corresponding values.
*/
Simple notation
var Vname1,vname2,vname3 = V1,v2,v3
Continue to simplify the wording
Vname1,vname2,vname3: = V1,v2,v3
Constants Define Const
BOOL defaults to False
Numeric type
String Go string is immutable
Iota Enum type
Go has a keyword iota, which is used when declaring an enum, and its default starting value is to add 1 to each additional line in 0,const.
const{
x = Iota//x = 0;
y = iota//y = 1;
z = Iota//z= 2;
When a w//constant declares an ellipsis, the default is the same literal as the previous value. Here implicitly says W = iota, so w = = 3. In fact, the above Y and Z can also not "= Iota"
}
Const V = iota//each time a const keyword is encountered, iota is reset, at which point v = = 0
Const (H, I, j = iota, iota, iota//h=0,i=0,j=0 Iota same row value)
Const (
A = iota//a=0
b = "B"
c = Iota//c=2
D, E, F = iota, iota, Iota//d=3,e=3,f=3
G = Iota//g = 4
)
Some rules of Go programming
The variable at the beginning of the capital letter is exportable, which is the public variable that the other package can read, and the lowercase letter begins with a non-exportable, private variable.
A function that starts with a capital letter is the same as a public function with a common keyword in class, and a private function that starts with a secret keyword.
Array expression arrays
var arr [N]type
in [N]type, n represents the length of the array, and type represents the types of the stored elements. Operations of an array are similar to other languages, and are read or assigned by []:
Slice dynamic Array
Slice has some simple operations
The default starting position for slice is 0,ar[:n] equivalent to ar[0:n]
The second sequence of slice is the length of the array by default, Ar[n:] equivalent to Ar[n:len (AR)]
If you get slice directly from an array, you can ar[:] because the default first sequence is 0, the second is the length of the array, which is equivalent to Ar[0:len (AR)]
Map
Make new operation
0 value