Go language tutorial manual

Read(26716) update time(2022-04-13)

Go is a new language, a concurrent, garbage-collected, fast-compiled language. It can compile a large Go program in a few seconds on a single computer. Go provides a model for software construction that makes dependency analysis easier and avoids most C-style include files and library headers. Go is a statically typed language, and its type system has no hierarchy. Therefore users do not need to spend time defining relationships between types, which feels more lightweight than typical object-oriented languages. Go is a completely garbage-collected language and provides basic support for concurrent execution and communication. By its design, Go is intended to provide a method for constructing system software on multi-core machines.


Go (also known as Golang) is a statically strongly typed, compiled, concurrent programming language with garbage collection capabilities developed by Google.

Robert Griesemer, Rob Pike and Ken Thompson began designing Go in September 2007, and later Ian Lance Taylor, Russ Cox joins the project.

Go is developed based on the Inferno operating system. Go was officially announced in November 2009, becoming an open source project and implemented on Linux and Mac OS X platforms, and later added implementation under Windows systems. In 2016, Go was selected as "TIOBE's Best Language of 2016" by the software evaluation company TIOBE.

Currently, Go releases a second-level version every six months (that is, upgrading from a.x to a.y).

Let’s experience the first Go program!

The first Go program

Instance

package main

import "fmt"

func main() {
   fmt.Println("Hello, World!")
}

Run instance»

Click "Run instance" button to view online instances

Go's syntax is close to C language, but the declaration of variables is different. Go supports garbage collection. Go's parallel model is based on Tony Hall's Communicating Sequential Process (CSP). Other languages ​​that adopt a similar model include Occam and Limbo, but it also has features of Pi operations, such as channel transmission. Plugin support is opened in version 1.8, which means that some functions can now be dynamically loaded from Go.

Compared with C, Go does not include functions such as enumeration, exception handling, inheritance, generics, assertions, virtual functions, etc., but it adds slice type, concurrency, pipes, garbage collection, Language-level support for features such as interfaces. The Go 2.0 version will support generics, but has a negative attitude towards the existence of assertions, and also defends that it does not provide type inheritance.

Unlike Java, Go has built-in associative arrays (also known as hash tables (Hashes) or dictionaries (Dictionaries)), just like the string type.

Tips: Our Go tutorials will help you learn Go from beginner to advanced. If you have any questions, please go to the PHP Chinese website Go Community to ask your questions, and enthusiastic netizens will answer them for you.

Go writing style

There are several regulations in Go, and these are mandatory. When the following regulations are not matched, compilation will generate an error.

  • There is no need to write a semicolon (;) after each line of the program.

  • Braces ({) cannot be placed in new lines.

  • if judgments and for loops do not need to be enclosed in parentheses.

Go also has a built-in gofmt tool, which can automatically clean up excess whitespace in the code, align variable names, and convert aligned spaces into tabs.

Go language features

  • Simple, fast, safe

  • ##Parallel, interesting, open source

  • Memory management, array safety, fast compilation

Go language usage

The Go language is designed to be used on web servers, storage clusters or similar A systems programming language used for giant central servers.

For the field of high-performance distributed systems, Go language undoubtedly has higher development efficiency than most other languages. It provides massive parallel support, which is perfect for game server development.

Content covered by this Go tutorial manual

This Go tutorial covers all basic and advanced knowledge of Go, including Go language structure, Go basic syntax, Go data types, Go functions, and Go operators , Go array, Go error handling, Go data conversion and Go language development tools and other knowledge introduction.

Tips: Each chapter of this tutorial contains many Go examples. You can directly click the "Run Example" button to view the results online. These examples will help you better understand and use the Go language.

Latest chapter


Go 语言开发工具 2016-10-18
Go 错误处理 2016-10-18
Go 语言接口 2016-10-18
Go 语言类型转换 2016-10-18
Go 语言递归函数 2016-10-18
Go 语言Map(集合) 2016-10-18
Go 语言范围(Range) 2016-10-18
Go 语言切片(Slice) 2016-10-18