Induction guide

As a new Golang backend developer, the first thing you do when you get to your desk is install your development environment. Each company’s project may be different, but the basic software must be installed. Now LET me introduce what software needs to be installed?

1. Compile software

If you want to run Golang code, you definitely need to install the Golang compiler, and we usually download the latest version, but companies may specify versions to avoid bugs.

2. Edit software

Once the Golang code is running, we need an editor that can edit the code. Notepad is the simplest, but it doesn’t have code hints. So in order to improve efficiency, we always install an editor with a code prompt function. Golang is currently supported by a number of editors, both free and paid. Here we recommend Visual Studio Code because it’s free, and most importantly because it’s lightweight, and there’s a Golang plugin.

3. Version management software

In the company, all the codes are put on the version server, so it is necessary to install version management software to participate in project development. The company usually uses SVN or Git. Git is recommended here because the branching mode of development is safer and more convenient. Most companies now use Git, and the Github repository uses Git, so Git is a must.

After you install the above three software, we can do Golang development. However, if you want to run your company’s projects, you may need to install other software to run them.

Database management software

Back-end projects typically use databases to store user data, order data, and so on. However, different projects may use different database software, including relational database MySQL and document database MongoDB. Install different database software based on project requirements. In addition, after the installation of the database software, also need to install a visual tool to visualize the operation of the database, to avoid all kinds of typing commands; MySQL visual chemical has many, commonly used Navicat, the official is MySQL Workbench, MongoDB is generally also the official MongoDB Compass. Companies tend to unify tools to reduce the cost of collaboration and communication between colleagues.

In general, the company’s projects are up and running once the above software is installed. Let’s go through the installation steps and configuration of each software in detail. Note: when downloading software, you must download it from the official website or from the company’s shared disk to avoid virus infection on your work computer.

Software Installation Demo

Install Golang

Official download address: golang.google.cn/dl/

Here we choose to download the Windows version of go1.14 as a demonstration:

If you want to change the installation path, you need to fill in your installation path in this step (tip: when installing all software, do not have Chinese installation path, in case some software does not support Chinese) :

Except the above installation path can be modified according to requirements, the other ones can be used by default. After installation, we need to verify whether the installation is successful.

  1. Press the shortcut key Win+R to open the command prompt window

  2. Enter Go Version in the window and press Enter

  3. If the go version information is displayed, the installation is successful

Install Visual Studio Code

The official download address: code.visualstudio.com/Download

Here we choose to download the Windows version as a demonstration:

Just like installing Golang, install Visual Studio Code, mostly by default. There are two points where you can make some choices:

At the first point, you can choose the installation path:

Second, optionally tick all the additional options:

After the installation is complete, double-click the software icon on the desktop to open the software for verification. If the installation is successful, it will be shown as follows:

Install the VSCode Go plug-in

With VSCode installed, we can create a Go file, such as test. Go, and enter a simple test code:

package main

func main() {
    fmt.Println("like it, itlike!")}Copy the code

You may find that the above code is buggy, there is no import FMT package, but you will find that VSCode does not tell you that there is an error in the code, just syntax coloring, because it lacks the Go plug-in, it cannot detect the code and prompt, install the Go plug-in as shown below:

Once installed, let’s take a look at our code. We can press Ctrl+S to save the file again and trigger the Go plugin.

You will notice that the code already has red line error, but it will not automatically help us import FMT package, the reason is that the Go plug-in also needs to install some Go libraries to help implement detection, hint, repair functions. In the right bottom corner of the image above you can see by the Go plug-in hint: gopkgs, goreturns command is not available, this writing is the Go tools, we choose to Install All at once All the Go tools used by the plug-in installed, in the province of trouble in the future. In addition, since most of these tools are hosted on Github, the Go plugin will alert you if there are any updates to the tool, so try to keep them up to date to make the Go plugin work better.

When everything is installed, you open the file again and press Ctrl+S to save it a few more times to trigger the Go plugin. Then you find that VSCode automatically adds the import “FMT” code for you, which automatically fixes it, as shown below:

Debugging runs the Go code

After installing the Go plug-in, we wrote code that had code hints and fixes, but we didn’t know how to debug and run the Go project. Go file. Then press F5 or choose Run->Start Debugging command to Run the current file. Then the following window displays Hello it, like it!

But in actual development, it’s not enough to just run, we also need to be able to debug code and add breakpoints. Just click on the left side of a line number to add a breakpoint, and then press F5 or select menu to enter breakpoint debugging mode, as shown below:

To illustrate, three lines of code have been added to the test.go file. In the figure above you can see that the left window shows the state of the variable at the breakpoint. The code has a background highlighting that the code broke at line 10. The bottom window also shows the output of the uppermost fmt.println. At this point, we can Continue executing the code by clicking a button like “>” on the debug panel (Continue).

Install Git

Official download address: gitforWindows.org/

Click Download to Download the Windows version:

Git installation is also very simple, in the second step to choose the software installation location, as shown in the picture below:

After the installation is complete, press Win+R to open the command prompt window, enter git version and press Enter. If you see the content below, it means that you have successfully installed.

Because Git exercises require a Git repository, I won’t demonstrate it in this article.

In addition, the installation of the database is not demonstrated in this article, and we will introduce the installation and use of the database when we really start to touch on the project.

conclusion

Golang, Visual Studio Code and Git are the most basic software in development. Golang development will be no problem with them. Of course, in the company’s projects, we will also use a lot of other auxiliary development software, these are selected according to the needs of the project to install.

If you encounter any problems in the process of building the Golang development environment or have Golang problems in your daily work, you can add wechat to ask for help: Itlike000