1. What is go language

Go (also known as Golang) is a static, strongly typed, compiled language developed by Robert Griesemer, Rob Pike, and Ken Thompson of Google. Go language syntax is similar to C, but the function has: memory safety, GC (garbage collection), structure and cSP-style concurrent calculation.

———– Baidu Encyclopedia

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Go is designed as a system programming language for large central servers with Web servers, storage clusters, and the like.

It is a compiled language.

It takes into account the execution characteristics of multicore computers. (Parallel programming)

The characteristics of

  1. Easy to learn
  2. High development efficiency
  3. Good execution efficiency (called C language of the 21st century)

It features efficiency, performance, security, and robustness

Application field

  1. Server-side development: log handling, file systems, monitoring services
  2. Container virtualization: Docker, K8S, Docker Swarm
  3. Storage: ETCD, TiDB, GroupCache
  4. Web development: HTTP/NET, Gin, Echo
  5. Blockchain: Ethereum, Fabric
  6. Cloud platform, at present, many foreign cloud platforms are using Go development, CloudFoundy part of the construction, the former VMare technical director out of his own apcera cloud platform.

Success stories

  • NSQ: Bitly’s open source message queue system is very high performance, currently they process billions of messages per day
  • Docker: a virtual packaging tool based on LXC, which can realize the construction of PAAS platform.
  • Packer: Image files used to generate 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’s open source log processing system
  • CBFS: Couchbase open source distributed file system
  • Tsuru: An open source PAAS platform that does exactly what SAE does
  • Groupcache: Memcahe is a caching system for Google’s download system
  • God: Similar to Redis’ cache system, but with distributed and extensible support
  • Gor: network traffic capture and replay tool

Locale installation

Download online: golang.org/dl/

Configure the GO environment variable. The installation directory of Go on your machine

CMD Enter go version to view the version

Hello World for Go

Create a go workspace and add it to the environment variables

Create the SRC, PKG, and bin directories

Create the demo.go file in the SRC directory

package main

import "fmt"

func main(a) {
   fmt.Println("Hello World !")}Copy the code

Open CMD in that folder and run go Demo.go

compile

Enter dir to view directory files

You will find an extra exe executable file whose default name is the name of the current folder

We can specify executable name compilation

Cross-platform compilation

By default, the executable files of our Go build are all executable files of the current operating system. If you need to compile the GO executable files of other platforms, you need to specify the platform before compiling

SET go_enabled =0 // Disable CGO, CGO does not support cross-platform SET GOOS= Linux // Target platform is Linux SET GOARCH= AMD64 // target processor architecture is AMD64Copy the code

Sublime opens it as a binary file that can be copied to Linux for execution

(Before executing the file, check whether the file has execution permission; otherwise, authorize the file.)

Go language project directory structure

Development tools (IDE)

Free VS Code (install go plug-in)

Charge Goland

vim

And so on…

The last

Let’s start the journey of Go!