This is a creation in Article, where the information may have evolved or changed.
Go Language Violence Primer 1
Program developers, not confined to language and technology, suitable and sufficient is the most perfect pursuit, 2017.05.04 began to learn the go language.
Personal website: http://www.linganmin.cn
Go Language Introduction
Go is an open-source programming language that makes it easy to build software that is simple, reliable, and efficient.
Go was developed from the end of 2007 by Robert Griesemer, Rob Pike, Ken Thompson, and later joined Ian Lance Taylor, Russ Cox, and eventually open source in November 2009, A stable version of Go 1 was released earlier in 2012. Now the go development is completely open and has an active community.
Install the Go language environment
Please google/baidu yourself, or refer to the official website:
First GO Program
package main // 给包命名import "fmt" // 引入fmt包,告诉 Go 编译器这个程序需要使用 fmt 包(的函数,或其他元素)/** * main函数 * main 函数是每一个可执行程序所必须包含的, * 一般来说都是在启动后第一个执行的函数 * (如果有 init() 函数则会先执行该函数) */func main() { fmt.Println("Hello, World!")}
Execute Go Program
go run [编写的go程序文件]// 例如go run demo.go
Go Language Basics Grammar
In the Go program, a line represents the end of a statement. Each statement does not need to end with a semicolon like any other language in the C family ;
, because the work will be done automatically by the Go compiler.
If you intend to write multiple statements on the same line, they must use a ;
man-made distinction, but this practice is not encouraged in real-world development.
Comments are not compiled, and each package should have related comments.
Single-line comments are the most common form of annotation, and you can use a //
single line of comments from anywhere. A multiline comment is also called a block comment, which has been prefaced with the /*
*/
end.
// 这是单行注释写法/** * 这是块注释写法 */
Identifiers are used to name program entities such as variables, types, and so on. An identifier is actually a sequence of one or more letters (A~Z and A~z) numbers (0~9) and underscores _, but the first character must be a letter or an underscore and not a number.
Based on previous programming experience in other languages, it is recommended to use 驼峰法
named
Here are the 25 keywords or reserved words that will be used in the Go code:
break|default|func|interface|selectcase|defer|go|map|structchan|else|goto|package|switchconst|fallthrough|if|range|typecontinue|for|import|return|var
In addition to the keywords described above, the Go language also has 36 predefined identifiers:
append|bool|byte|cap|close|complex|complex64|complex128|uint16copy|false|float32|float64|imag|int|int8|int16|uint32int32|int64|iota|len|make|new|nil|panic|uint64print|println|real|recover|string|true|uint|uint8|uintptr
Procedures generally consist 关键字
of,,,, 常量
变量
运算符
类型
and 函数
These delimiters may be used in the program: parentheses ()
, brackets, []
and curly braces{}
These punctuation marks may be used in the program: .
,, ,
;
, :
and…
The declaration of a variable in the Go language must be separated by a space, such as:
var age int;
Go Language data type
In the Go programming language, data types are used to declare functions and variables.
Data types appear to be in order to divide the data into the required memory size of the data, programming when you need to use big data when you need to apply for large memory, you can make full use of memory.
The value of a Boolean can only be a constant true or false. A simple example: var a bool = Fale
Integral int
and floating-point float
, the Go language supports integer and floating-point numbers, and natively supports complex numbers, where the operations of bits are complement-oriented.
A string is a sequence of characters concatenated with fixed-length characters. The string of Go is connected by a single byte. The byte of the Go language uses UTF-8 encoding to identify Unicode text.