当前位置:网站首页>Go installation and configuration (1)
Go installation and configuration (1)
2022-06-30 06:44:00 【seven six nine】
Install the test
install
Download the installation package on the official website
Address https://golang.google.cn/dl/
When the download is complete , Execute installation file , Continue to the next step to complete the installation ( The installation position is optional )
open cmd perform go version Check whether the version number can be queried , Here's the picture .
To configure
To configure GOPATH
Create a new folder as the workspace , Position at will , Contents in English 
Create a new... In the system variable GOPATH Variable , The value is the new folder address above 
because Go A default workspace is assigned during installation , In user variables , You need to remove

Then confirm one by one , Preservation
When the configuration is complete , Create three folders in the new folder

After creation, enter bin Folder copy address , In the user environment variables PATH Add bin Folder address


Change the default variable to bin Directory address
After the save go env see

vs code
Editor's words , I'm using vscode
Download from the official website and install by yourself
Open the editor , Click expand , download go Language extension 
Want to download Chinese plug-ins , Search and install by yourself
Open the previously created with the editor src Folder , Open and create Folder hello, Create the file again main.go

A plug-in is also recommended here Tabnine, It can be completed automatically , Very cool 
test
Start writing the first one go Program
package main
import "fmt"
func main() {
fmt.Println("hello GO")
}

When writing, the prompt always pops up in the lower right corner , These things are installed go Plug ins are used to extend code , Downloading usually fails , Because these packages are on the Internet . At this time, you can set GOPROXY( agent ) Just go
cmd Execute the following two lines respectively
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
Verify that the configuration is successful

Windows Platform press Ctrl+Shift+P,Mac Platform press Command+Shift+P, This is the time VS Code An input box will pop up , Here's the picture 
Let's type... In this input box >go:install, The following will automatically search for relevant commands , We choose
Go:Install/Update Tools This command
Check and press enter to execute the command ( Or click the command with the mouse )
After downloading , The successful output is shown in the figure :

You can see an error here
Enter the console terminal to run the command go mod init demo( Project name , Set it up by yourself )
Save the following code to main.go
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
Next, execute the command , Will download the necessary packages
go mod tidy

You need to know more about go mod knowledge
Baidu
Then you can write the code 
边栏推荐
猜你喜欢
随机推荐
Deep learning --- the weight of the three good students' scores (3)
Picture.....
手机开户一般哪个证券公司好?还有,在线开户安全么?
RT thread migration to s5p4418 (III): static memory pool management
程序猿入门攻略(十一)——结构体
Simple example of class template
SOC_AHB_SD_IF
Set in set (III)
Centos8 install redis
Loading class `com. mysql. jdbc. Driver‘. This is deprecated. The new driver class is `com. mysql. cj. jdb
阿里云买的40G高效云盘挂载只有20G
Image processing 7- image enhancement
A small template (an abstract class, a complete process is written in a method, the uncertain part is written in the abstract method, and then the subclass inherits the abstract class, and the subclas
C language: exercise 3
Unable to access the Internet at win10 /11 hotspot
原来你是这样的数组,终于学会了
[untitled]
File Transfer Protocol,FTP文件共享服务器
1.4 - fixed and floating point numbers
Why does ETL often become ELT or even let?








