This is the second day of my participation in the November Gwen Challenge. Check out the details: the last Gwen Challenge 2021

Introduction to Go

What is the Go language

Go is Google’s second open source programming language released in 2009.

The Go language is optimized for programming applications on multiprocessor systems, and programs compiled using Go can be as fast as C or C++ code, while being more secure and supporting parallel processes.

Go language is very expressive, it is concise, clear and efficient. Thanks to its concurrency mechanism, programs written with it can make very effective use of multi-core and networked computers, and its novel type system makes the program structure flexible and modular.

Go code not only compiles to machine code very quickly, but also has a convenient garbage collection mechanism and a powerful runtime reflection mechanism. It is a fast, statically typed compiled language that feels like a dynamically typed interpreted language.

Origin of Go

Go was first spoken in 2007 and was first spoken in 2009. It began on September 21, 2009 as part of Google’s 20% part-time program, in which employees spend 20% of their free time working on Go. The three leaders of the project are all well-known IT engineers: Robert Griesemer, who worked on the Java HotSpot VIRTUAL machine; Rob Pike, Director of the Go Language Project and a member of the Bell LABS Unix team, has worked on projects including Plan 9, the Inferno operating system and the Limbo programming language; Ken Thompson, a member of the Bell LABS Unix team and one of the founders of C, Unix, and Plan 9, co-developed the UTF-8 character set specification with Rob Pike. Since January 2008, Ken Thompson has been working on a C compiler to extend the design ideas of Go.

Ivo Balbaert. Go: The Way to Go (Chinese) (Kindle location 112-117). Posts and Telecommunications Press.

Language features of Go

  • Simple, fast and safe
  • Parallel, fun, open source
  • Memory management, array security, fast compilation

Application scenarios of GO

  • Server programming, such as logging, data packaging, virtual machine processing, file systems, etc
  • Distributed systems (database agents, middleware)
  • Network programming (Web application, API application)
  • Cloud platforms such as Docker and K8S are all developed with GO language

Go Language official website

https://golang.org/
Copy the code

If access is slow or unavailable, please visit Google China’s official website

https://golang.google.cn/
Copy the code

The language Windows /. MacOS/Linux/raspberryPi installation is the first step in programming development environment, is also the simplest. Now let’s start installing the latest go development environment. This article is available on the latest download page for go version 1.12.9

Starting with Go 1.13, the Go command uses the Go module image and the checksum database run by Go to download and verify modules by default. For privacy information on these services, see proxy.golang.org/privacy; See the go command documentation for configuration details, including how to disable these servers or use different servers.

Windows and MAC are the easiest to install

Install Go on Windows MSI

  • Download the installation package MSI filehttps://dl.google.com/go/go1.12.9.windows-amd64.msi.1.12.9You can replace it with the version you want
  • Double-click after downloadingGo1.12.9. Windows - amd64. MsiInstallation file, agree to the agreement, choose the installation path,Check automatically Add environment variables to you
  • Check whether go is installed successfullygit-bashorpowershellorCMDType in thego env
  • Users inside the wall set environment variablesgoproxyhttps://goproxy.ioorhttps://mirrors.aliyun.com/goproxy/

MacOS PKG install Go

  • Download the installation package PKG filehttps://dl.google.com/go/go1.12.9.darwin-amd64.pkg.1.12.9You can replace it with the version you want
  • Double-click after downloadingGo1.12.9. Darwin - amd64. PKGInstallation file, agree to the agreement, choose the installation path,Check automatically Add environment variables to you
  • Check whether go is installed successfullyterminalType in thego env
  • Users inside the wall set environment variablesgoproxyhttps://goproxy.ioorhttps://mirrors.aliyun.com/goproxy/ vim ~/.bashrcorvim /etc/profileAdd at the end of the fileexport GOPROXY=https://goproxy.ioorexport GOPROXY=https://mirrors.aliyun.com/goproxy/ :wqCommand hold file, executed in terminalsource /etc/profileorsource ~/.bashrc

Linux /centos/ Ubuntu binary install Go language environment

Download the binary installation package

VERSION = '1.12.9'; Amd64, arm (Raspberry PI PI 3), arm64, S390x, ppc64le GZFILE = "go $VERSION. $OS - $ARCH. Tar. Gz" # download installation name contains the ARCH wget "https://dl.google.com/go/${GZFILE}"; rm -rf /usr/local/go; /usr/local -xzf $GZFILE; /usr/local -xzf $GZFILE; Unzip the file to /usr/local/goCopy the code

Users to set the environment variable inside the wall goproxy to https://goproxy.io or https://mirrors.aliyun.com/goproxy/ vim ~ /. Bashrc or vim/etc/profile added at the end of the file Export GOPROXY = https://goproxy.io or export GOPROXY=https://mirrors.aliyun.com/goproxy/ : wq command to keep files, Run the source /etc/profile or source ~/. Bashrc command on the terminal

Of course, the above command can also be used on macOS, but choose the appropriate ARCH operating system

Windows setup GoProxy tutorial, download the go dependency package outside the wall

On Windows Powershell, you can run the following commands.

# Enable the go modules feature $env:GO111MODULE=on # Set GOPROXY environment variable https://mirrors.aliyun.com/goproxy/ $env:GOPROXY=https://goproxy.ioCopy the code

Now, when you build and run the application, GO will get the dependencies through the GoProxy proxy.

If your Go version > = 1.13, the GOPRIVATE environment variable controls which modules the Go command considers private (not public) and therefore should not use a proxy or checksum database. For example, go version > = 1.13

go env -w GOPROXY=https://goproxy.io,direct # Set environment variable allow bypassing the proxy for selected modules # Corp.example.com Dependencies on package names Do not use goProxy go env -w GOPRIVATE=*.corp.example.comCopy the code

The End

Online communication tools: in your terminal type SSH [email protected]

Type SSH mojotv.cn hn in your terminal to view the latest Hacknews