This is a creation in Article, where the information may have evolved or changed.
Note: I will finish my translation work before Chinese New year because I have a lot of work in the years ago.
This is the first tutorial to get started with the go language
What is Golang
Go is a programming language created by Google, open-source, compiled, and statically typed.
The main focus of Golang is to make it easy and easy to develop highly available and scalable Web applications.
Why Choose Golang
Why choose Golang as a service-side programming language with so many other programming languages?
Here are some of the benefits I've found about the go language
- Can be directly compiled into machine code, do not rely on other libraries, glibc version has certain requirements, deployment is to throw a file up to complete.
- Static type language, but there is the feeling of dynamic language, static type of language is can be compiled at the time to check out the most hidden problems, dynamic language feeling is that there are a lot of packages can be used, writing up the efficiency is very high.
- Language level support concurrency, this is go the biggest feature, innate support concurrency, I once said a word, innate gene and plastic surgery is a difference, everyone is as beautiful, but you like plastic surgery or natural genetic beauty? Go is a gene that supports concurrency, makes full use of multicore, and is easy to use concurrently.
- Built-in runtime, which supports garbage collection, is one of the features of dynamic languages, although the GC is not perfect at the moment, but it is sufficient to cope with most of the situations we can encounter, especially after Go1.1.
Easy to learn, go language authors have a C gene, then go naturally has a C gene, then the GO keyword is 25, but the ability to express is very powerful, almost support most of the features you have seen in other languages: inheritance, overloading, objects and so on.
- Rich standard library, go now has built up a large number of libraries, especially the network library is very powerful, my favorite is this part.
- Built-in powerful tools, the go language inside a lot of tool chain, the best should be gofmt tools, automated format code, can make the team review so simple, the code format is identical, it is difficult to think differently.
- Cross-platform compilation, if you write the go code does not contain CGO, then you can do the window system to compile the application of Linux, how to do it? Go refers to the Plan9 code, which is information that does not depend on the system.
- Embedded c support, said the author is the author of C, so go inside can also directly contain C code, using the existing rich C library.
What go is suitable to do
- Server programming, if you used C or C + + to do things, go to do a good job, such as processing logs, data packaging, virtual machine processing, file system and so on.
- Distributed systems, database proxies, etc.
- Network programming, which is currently the most widely used, including Web applications, API applications, download applications,
- In-memory database, some time ago Google developed groupcache,couchbase part of the build
- Cloud platform, at present, many foreign cloud platform in the use of Go development, cloudfoundy part of the formation of the former Vmare technical director himself out to engage in Apcera cloud platform.
Installation
Golang supports all third-party operating systems for MAC, Windows, Linux. You can download binary files for the platform from the following link https://golang.org/dl/
Mac OS
Download OS X installer from https://golang.org/dl/
Double-click to start the installation. After installation is complete, Golang is installed in the/usr/local/go directory and/usr/local/go/bin is added to the system environment variable.
Windows
Download the MSI installer from https://golang.org/dl/. Double-click the installation file according to the installation prompts until the installation is complete. Golang will be installed in the c:\Go
directory, the c:\Go\bin
directory will be added to the system environment variables
Linux
Download the tar file from https://golang.org/dl/, unzip it to the/usr/local directory using the Unzip command, and add/usr/local/go/bin to the system environment variable.