The old cat’s GO learning series blog has officially started, I believe we used to learn a programming language also have experience, we generally start from the environment, here, we also follow the old cat from the beginning of the building environment.

GO language installation

To start, we need to download the GO language installation package. The official website of GO abroad is golang.org/, of course, this is limited to qualified partners to download the official website. We generally have restrictions on downloads, but it doesn’t matter. In China, there is also a corresponding website called golang.google.cn/. There is also a website, almost a GO learning community, available at studygolang.com/dl. The latter is recommended, and the relevant Chinese and English documents are also relatively complete. Visit studygolang.com/dl to open it like this:

Select an installation package based on your own environment and install it step by step. This is too easy. I’m not going to expand it.

After the installation is complete, run the go version command on the command line to get the relevant version information. Because the old cat has been installed before, it is not the latest version, so the version information after installation is as follows.

Configuration of the domestic mirror

An important point about setting up the GO environment is the configuration of the image. You can enter the command go env to see some configuration of the environment of the related GO language.

Goproxy set

The current computer environment of the old cat is Windows, so you can see the above information, there is an important attribute information called goproxy, the current setting of the old cat is goproxy.cn,direct, after the installation of the default address should be https://proxy/gola…

If there is no condition on the network, configure the default address should be unable to pull the relevant dependencies, so here, it is best to configure into our domestic mirror.

In fact, the old cat configuration domestic mirror mainly refer to this website: goproxy.cn/, after opening, there are details above…

GO111MODULE set

In the screenshot above, we can also see a more important attribute, which is GO111MODULE. The old cat queries some other data.

Before GO 1.11, if you want to implement package management for GO language, you can only rely on third-party libraries, such as Vendor,GoDep and so on. But after that, we can implement package management based on this switch.

GO111MODULE can be switched on or off with three values: off, on, and auto. The default value is auto.

  • GO111MODULE=off Without module support, go will look for packages from GOPATH and vendor files.
  • GO111MODULE=on module support, go will ignore the Gopath and vendor folder, only according to go.mod download dependencies.
  • GO111MODULE=auto Enable module support outside $GOPATH/SRC and if the root directory has the go.mod file.

In fact, the above description sounds like a half-understanding of the appearance, in fact, there is no need to tangle too much, because in the later in-depth process, we will slowly understand. Of course, the old cat will discuss it in depth when sharing “dependency management” with you. In this case, we set the property to ON. The setup command is also above it. It is important to note that you need to set it to lowercase on when setting it. Don’t make a mistake.

Development tool Configuration

The above describes the configuration of the related GO environment. In fact, this is OK, so we can choose a more convenient tool to start the configuration after the code. Actually go related development tools are many, such as vi, emacs, idea, eclipse, vscode, sublime does.. + go plug-in. Of course, IDE series also have Goland, you can also go to the official website to download. The old cat will next one of the development tools, IDEA+GO plug-in way, because the old cat is JAVA backend, used to IDEA, so I will first introduce this configuration. Of course the relevant configuration of other development tools, we can go to Baidu or Google to find.

Idea plug-in

The first plug-in, of course, is the Go plug-in, as follows:

This is the local environment of the old cat, which has been installed.

Another plugin is File Watcher, which you can search for and install. This tool is actually an automatic formatting tool, when we save the file will be formatted according to the GO language standards.

After the installation, we restart IDEA and create a GO project to write a GO version of HELLO WORLD. Specific as follows

We need to create a GO MODULE project. An idea here is that when proxy is used, it will default. We will change it to goproxy.cn,direct, and of course this path is the proxy we configured above. Since the project does not involve SQL for the time being, we can go directly to the next step and complete the name.

You can take a look at the old cat project.

Note that when I do a new file, SELECT simpleApplication, hit Run, and the helloWorld is displayed on the console.

The file Watcher plugin does not currently work, but we need to set it as follows:

First we need to remove this setting.

Then we search the file again watcher selected after click + number, add goimports plugin, if not see goimports plug-in, you switch to the command line, enter: go get -v golang.org/x/tools/cmd/goimports can.

After adding the old cat like this, then restart IDEA. How to verify that the installation is successful, actually very simple, just add a space in front of the parentheses, and then save to see the effect.

Write it at the end of the chapter

And now you’re ready to run Hello World. Later, the old cat will slowly introduce the grammar of GO language, containers and so on. Don’t fall behind! Of course, what questions are also welcome to pay attention to the old cat’s public number “programmer old cat”. We discuss together and make progress together.