Basic knowledge of Go language (1): Basic introduction

1. Introduction

The Go language, also known as Golang, was released by Google in 2009. In recent years, it has risen rapidly with the development of cloud computing, microservices, and distribution, and has become one of the mainstream programming languages. Similar to Java, it is a static , Strongly typed, compiled programming language, born for concurrency, so it is naturally suitable for concurrent programming (network programming).

At present, the Go language supports multiple platforms such as Windows and Linux, and can also be directly executed on mobile terminals such as Android and iOS. From a business perspective, the Go language is widely used in cloud computing, microservices, big data, blockchain, Internet of Things, artificial Intelligence and other fields have a wide range of applications. So now is the time to learn.

2. The author of the Go language

insert image description here

The fathers of the Go language (from left to right are Robert Griesemer, Rob Pike and Ken Thompson)

Ken Thompson, one of the founders of C language Unix and Plan9, designed and implemented the Unix operating system in the 1970s, and also designed UTF-8 encoding with Rob Pike.

Rob Pike not only designed the UTF-8 encoding, but also developed the distributed multi-user operating system Plan9 Inferno operating system and the Limbo programming language.

Robert Griesemer works at Google and is responsible for the code of the Google V8 engine in the Chrome browser.

That afternoon, in his office at Google's Mountain View headquarters, Rob Pike kicked off the compilation and build of a C++ project. Judging by past experience, this build takes about an hour. Using this time, Rob Pike sat down with Robert Grismore and Ken Thompson and exchanged ideas about designing a new programming language.

The reason for this idea is that at that time, Google mainly used C++ language to build various systems, but the huge complexity of C++, slow compilation and construction speed, and insufficient support for concurrency when writing server programs made the three big The guy felt very inconvenient, so they wanted to design a new language. In their initial conception, this new language should be able to bring happiness to programmers, match future hardware development trends, and be suitable for developing Google's internal large-scale network service programs.

They started designing the Go language in 2007 and officially released it in 2009. Go language not only has the development speed of dynamic languages ​​such as python, but also has the performance and security of compiled languages ​​such as C/C++. Also known as the C language of the 21st century, it can not only access the underlying operating system but also provide powerful network programming, concurrent programming, and distributed programming.

After the Go language project was open sourced, the Go language also ushered in its own "mascot", a gopher designed by Rob Parker's wife, Renee French. It has become a symbol of Go programmers all over the world, and Go programmers are also nicknamed Gopher.
insert image description here

3. Go Language Features

Open source Go itself is written in the Go language.

Speed ​​is the only thing that can't be broken in martial arts. Choose a fast language such as C language, but it is difficult to develop. There are many errors in compilation speed dependency and runtime, or some languages ​​have too many dependencies. The most important one is the interpreter itself, such as The Java language requires a virtual machine to run code, and javascript and node.js are maintenance nightmares. Especially with callbacks. The Go language was designed with fast compilation in mind. He can be like any other interpreted language, you will not notice that he is compiling. The Go language realizes the perfect combination of development efficiency and execution efficiency, allowing you to write C language (performance) code like writing Python (efficiency) code.
insert image description here

Safety As a strongly typed static language, it is also safe because it has its own garbage collection mechanism. Because Go's language design has the ability to manipulate pointers like C language, but it is usually not as dangerous as C language, because its memory is managed by Go itself.

Concise Code Go language is not only fast in compilation, but also concise and easy to read.

Compiled Does not require virtual machine support, can be directly compiled into machine code, and the compiled file does not need to depend on other package files.

Cross-platform Go language has cross-compilation, which can be easily compiled to run on a specified platform: such as OS X, Linux, Windows, Arm or other platforms.

Automatic Garbage Collection Garbage collection during the running of the program is generally the sole responsibility of the Go runtime system. However, Go also allows us to intervene in this work.

Built-in packages The Go language has almost all the standard libraries you can use. For example, http network protocol package, json analysis package, time time package and so on. This kind of fragmented stuff takes up most of the time in a system.

Complete build tool The excellent built-in command tool of Go language, it comes with many powerful commands and tools, through them, you can easily complete a series of tasks such as acquiring, compiling, testing, installing, running, and analyzing Go programs. For example, the code format is automatically set, and the problems in the code are checked. The go fmt command automatically formats the code after each save.

Native concurrent programming Concurrency is a highlight in the Go language. The smallest unit of concurrency is a coroutine, which is a micro-thread but different from a thread. Coroutines are created by the Go language itself and scheduled by the runtime runtime of the Go language itself. Problems that require threads to solve in other languages. There is a limit to the number of threads that a computer can open. In the Go language, it is easy to start a coroutine for processing, because the coroutine is very small and does not occupy computer resources. A computer can easily open thousands of coroutines. In this era of big data, the language that can handle large amounts of data and is simple, fast and open is none other than Go.

4. Which companies are using the Go language

There are at least 1 million Go programmers in the Go community. More and more companies are embracing the Go language, the most famous companies using the Go language are Google, Docker, Dropbox, Heroku, Uber, etc. Domestic companies such as Didi, Tencent, Ali, JD.com, iQiyi, Xiaomi, 360, Meituan, Lvmama.com, Douyu Live, Tantan, etc. are all using the Go language. The background including Bilibili has also shifted from java to Go, which shows the popularity of the Go language. Most of the popular and reliable works of modern cloud computing infrastructure software you can think of are written in Go, such as: Docker, Kubernetes, Prometheus, Ethereum (Ethereum), Istio, CockroachDB, InfluxDB, Terraform, Etcd, Consul and so on. Of course, this list is still growing, which shows that the influence of the Go language is already very strong.

5. GO language project

docker : A virtual packaging tool based on lxc, which can realize the formation of PAAS platform.

kubernetes : Kubernetes is a container orchestration engine open sourced by Google, which supports automated deployment, large-scale scalability, and application container management. When deploying an application in a production environment, it is common to deploy multiple instances of the application in order to load balance application requests

Blockchain : BTCD is a bitcoin implementation of a full node implemented in the go language

nsq : Bitly's open source message queuing system with very high performance. Currently they process billions of messages every day

packer : used to generate image files for different platforms, such as VM, vbox, AWS, etc., the author is the author of vagrant

skynet : distributed scheduling framework

Doozer : distributed synchronization tool, similar to ZooKeeper

Heka : mazila open source log processing system

cbfs : couchbase open source distributed file system

tsuru : An open source PAAS platform, which has exactly the same functions as SAE

groupcache : a caching system written by the author of memcahe for Google's download system

god : A cache system similar to redis, but supports distribution and scalability

gor : network traffic capture and replay tool

Guess you like

Origin blog.csdn.net/weixin_44816664/article/details/131549728