Hi, everybody, I’m here to give you the Amway Go language.

A quick cut: I first learned the Go language in July 2013. After trying to understand it, my classmate Amway (thank you @Slowfei), I was deeply attracted by its unusual syntax, logic, keywords and weird formatting format.

  • The earliest contact version is Golang 1.1.8
  • Only 25 keywords (decisively abandoned Java.net C#, why are you so fat?)
  • The simple declarator “:=” is declared and assigned, and the system automatically inferences the type. The var keyword is not required
  • Coroutines go func () {} ()
  • The return value more
  • Format time t.faormat (“2006-01-02 15:04:05.999999999-0700 MST”)

I did not accept refutation. At that time, MY knowledge of programming languages was limited

Golang profile

Go is a general-purpose computer programming language created by Google. The bright spots and the rapid rise of programming languages attract programming enthusiasts. In recent years, Go has become a popular programming language and has successfully entered the mainstream. Many big companies have also embraced the Go language, including Alibaba, Xiaomi, Didi, Toutiao, Qihoo 360, JD.com, Bilibili, Zhihu, Meitu, Cheetah Mobile, etc.

Go programs can be installed on servers with Windows, Linux, FreeBSD and other operating systems, and used to provide basic software support, API services, WEB services, WEB services, and so on. The Go language has also been actively explored on mobile and is now available on Android and iOS. In addition, the Go language has joined with WebAssembly to join the WASM platform. That means it won’t be long before Internet browsers can run programs written by Go.

From a business perspective, Go has been booming in cloud computing, microservices, big data, blockchain, Internet of Things and other fields. Some are already highly used, and some have their place. Even in data science and artificial intelligence, where Python is king, the Go language is slowly infiltrating and emerging. (Cite 1.)

As an early learner and user, I have witnessed the development and rise of Go over the years with many enthusiasts.

  • Go 1.5 Bootstrap (write programs in the Go language to implement the Go language itself)
  • Go 1.7 Rapid GC (Tricolor Mark-and-sweep algorithm)
  • Upgrade the built-in tools in Go 1.10 (reference 3.)
  • Go 1.11 Modules

Go website: golang.org recommend: studyGolang.com

Direct code

The above introduced so much, then we don’t force, directly on the code!

Well, that’s the end of basic introduction, thanks for watching!

No, no, no. Just kidding.

Installing a supporting environment

First of all, the first thing is to install the relative language support package according to their computer’s computing architecture and operating system. Goalng Language Support package

  • Github.com/golang/go/r…
  • studygolang.com/dl

Once the download is complete, take a look at the three important environment variables that go needs (less so with the introduction of gomOD capabilities)

Base environment variables (Windows as an example)

GOROOT: Indicates the path for storing the Go source code

GOPATH: The Go workspace, where your own code is stored

GOBIN: This parameter is not set by default

So let’s focus on GOPATH GOPATH: refers to a directory path, which is the workspace path where your code resides. It contains three main file directories (all named in lowercase) :

  • Bin: Executable File directory after build
  • PKG: Archive File directory
  • SRC: Source File directory

The directory structure is as follows:

With that in mind, it’s time to give Go a try. Go provides download packages in ZIP and MSI formats that are suitable for Windows environments.

  • If it is an MSI installation package, double-click it. The default directory is C :/go. After the installation is complete, check whether it existsGOROOT,GOPATH,GOBINThese three system environment variables.
  • If you are using zip, you can choose to decompress it to your preferred path. And then configure it manuallyGOROOT,GOPATH,GOBINThese three system environment variables.

Then remember to add %GOROOT\bin% to the system path so you can use the go command on the command line.

With all this set up, let’s open the command line for typinggo versionEnter! (if nothing goes wrong)

You can see which version of the GO language, operating system, and computing architecture you are using.

Let’s say Hello World! !!!!

If all is well, let’s implement a Hello World!

SRC create a hellogo folder, go to the hellogo folder, create a main.go file, the final file structure is as follows:

Double click on the main.go file, open it with Notepad, and copy the following code to save

package main

import "fmt"

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

Run the CD command to go to the directory where the file is stored. In the command line, enter:go run main.goThen you get something like this. It’s that simple!

Why is GOPATH the most important?

If it’s so simple, why is GOPATH the most important?

GOPATH is where virtually all of the operations of a Go language project during its lifecycle, such as coding, dependency management, building, testing, installation, and so on, revolve around GOPATH and workspaces.

GOPATH can be a single directory path or multiple directory paths. Each directory represents a work space in Go, where the source code is organized in the basic unit of code packages. Directories can have subdirectories, so code packages can have subcode packages. A code package can contain any number of source files with the.go extension. These files need to be declared to belong to the same code package. The code package name is usually the same as the directory in which the source files reside. If the name is different, the package name will prevail during the build and installation process. (Cite 4.)

In other words, GOPATH can point to a directory containing one or more projects, each of which is a workspace, and each workspace can be a package. Go source files end in.go files.

Some of the history

New variables in Go 1.10

GOCACHE & GOTMPDIR

  • GOCACHE Go Cache mechanism. The Go Build Tool maintains a cache of the compiled results of a package along with some metadata. The cache is located by default in the user cache directory specified by the operating system, where the data is reused for subsequent builds
  • GOTMPDIR is used to set the path of temporary files created and used by the Go Tool to prevent certain system pairs/tmpThe file is read-only

If there is no specific prompt during compilation, installation, or running, but the file is not generated correctly after completion, you can try to modify this variable path.

Go package management tool

Before GO V1.5, package management in go was in Monorepo mode, that is, all packages were placed in the path specified by GOPATH.

Go V1.5 introduced vendor’s package management mode and the community also maintains a deP package management tool.

Go Module has been added in GO V1.11 as the official package management form, but it cannot be used directly.

When go V1.13, the Go Module is gradually polished to maturity and turned on by default, then it is very convenient to use the Go mod to manage the Module.

now

The language specification changes in the GO V1.15 update are essentially minimal. Major improvements include tooling, compiler performance, and the standard library.

More details can be found at blog.golang.org/go1.15-prop… (Science Internet) Domestic translation: learnku.com/docs/go-blo…

Finally, why are time formats weird?

Go Time Format source sectionLegend: This is the moment when the seed idea of Golang was born

At the end

Thank you for watching

The resources

  1. The Go language core 36 | preview – geek time piece Author: hering
  2. The Go language: theory and practice of real-time GC – segmentfault.com/a/119000001…

2.1:5 picture to see all the Go language evolutionary history of GC: blog.csdn.net/erlib/artic… 2.2: Golang Github “Suggestion: Eliminate STW Stack Rescan” : github.com/golang/prop… 3. “Go to watch a few changes in 1.10” : ju. Outofmemory. Cn/entry / 34457…

🏆 technology project phase ii | and I Go those things…

Copyright notice: the copyright of this article belongs to the author Lin Xiaoshuai, shall not be reproduced without authorization and second modification. Reprint or cooperation please leave a message and contact information below.