Tutorial launched in: wechat official account “Go Programming Time”
1. Download and install the Go language
Download it at golang.google.cn/dl/
After downloading, directly double-click the MSI file for installation. I used to install the software in the Program Files directory under my E disk
Click Next until the following interface appears and the installation is complete.
2. Configure the Goland environment
Learning a programming language and using a good IDE can save you a lot of trouble.
I’m used to using PyCharm for Python projects because BEING used to JetBrains style IDES saves me a lot of the cost of getting familiar with new ides, so I’ll stick with JetBrains IDE for Go: Goland.
Goland download address: download.jetbrains.com/go/goland-2…
Double-click the downloaded EXE file. In addition to selecting the installation path, WHICH I used to change to disk E, select Next all the way until the following interface, select all according to your needs (it is recommended to select all)
Then go all the way to Next until the following interface appears. After installation is complete, select Run Gogland to Run immediately.
Goland is not available if you have not purchased the JetBrains activation code.
In order to make our learning more smooth, we will teach you how to get the use of Goland by cracking it.
First download the patches: c.biancheng.net/uploads/cou…
The downloaded ZIP package contains three files
- Jetbrains -agent.jar: Patch cracking
- Resources_cn. Jar: Chinese patch
- TXT: indicates the activation code
Copy jetBrains. Jar to your Goland installation directory in bin: E:\Program Files\JetBrains\ Goland 2019.2.3\bin
Then open the two files with an editor
Add the following line to the last line, and modify the following values according to your path
- javaagent: E: \ \ Program Files \ JetBrains \ GoLand 2019.2.3 \ bin \ JetBrains - agent. The jarCopy the code
Then go back to your Goland startup screen, click on Activation Code, copy the Activation code from Activation code.txt, fill it in, and click OK
Now that your Goland is ready to use, create my project directory and set up GOROOT.
After creating Project, click Files->Settings->GOPATH to add our Project directory F:\ go-player
Click on any go file and you will see the configuration entry at the arrow below. Click to enter and configure the GO runner.
Follow the instructions below to configure.
Remove parameter prompt
Set the goproxy
Set up goimports (automatic formatting plug-ins) to prompt you to click Yes to download the installation if you haven’t already installed it.
At this point, the environment is configured.
In the project root directory, create the following three folders, and create a hello.go file in the SRC directory.
Click the Run button, and in the console we see the familiar Hello, World!
3. Configure the VS Code environment
Set up user-level environment variables ahead of time
GOPATH = F:\Go-Player
PATH = %GOPATH%\bin # append
Copy the code
Someone asked in the comments yesterday, what are GOPATH and GOROOT? Why do I need to set this? Recall that when you learned Python, when you installed the Python interpreter, did you also set environment variables? It’s similar here.
GOROOT: In GO language represents the installation path of GO language compiler, tools, standard library, etc. It can tell the system where your go.exe is stored. If you do not set it, the system will not recognize it when you execute GO get and GO install.
The GOPATH environment variable represents Go’s working directory, which specifies where to look for Go packages, executables, and so on, and can be multiple directory representations. Here I set it to my workspace (directory is up to you) : F:\ go-player. If not, it defaults to the Go folder in your user directory.
Due to some reasons, we could not access the official source of Go in China, which led to the failure of downloading some packages.
There are many solutions, but for now, the easiest is to configure a proxy.
How to configure it? All it takes is one command.
$ go env -w GOPROXY=https://goproxy.cn,direct
Copy the code
At this point, the typical working directory structure for a GO project looks like this:
- Bin directory: contains the executable program, note that it is executable, do not need to explain the execution.
- PKG directory: Contains the packages or libraries to use.
- SRC directory: This contains the go code source files, which are still organized by package.
So later I create the GO working directory, also according to this standard, first to explain.
Next, start configuring the VS Code environment.
Open your VS Code software, first confirm that the environment variables you set have taken effect, go to Terminal -> New Terminal, use CMD to view the environment variables.
As shown above, my environment variable is OK, if your output is pointing to your user directory: %USERPROFILE%\go I suggest you don’t bother (because no matter how many times I restart VS Code, its GOPATH will always point to %USERPROFILE%\ Go) and restart your computer directly.
After that, we will download two repositories from Github. The reason why we need to download them manually is because there are walls, and many plug-ins will fail to download online.
Create a directory SRC /goland.org/x/, go to the directory, and run the following command
$ git clone https://github.com/golang/tools.git
$ git clone https://github.com/golang/lint.git
Copy the code
Click file-Open Folder to install two plug-ins:
The first is an extension to the Go language
The second is Code Runner, which allows your VS Code to compile programs that run Go.
Click on any go file and it will prompt you to Install some tools in the lower right corner. Click Install All
Then you can see the installation progress in OUTPUT
The installed exe file will be placed under %GOPATH%/bin, i.e. F: go-player \bin
The SRC directory structure looks like this
At this point the environment is configured, you write HelloWorld, and run the view output, and you’re done.
This article was automatically published by ArtiPub