当前位置:网站首页>GO安装以及配置(1)
GO安装以及配置(1)
2022-06-30 06:37:00 【七六九】
安装
官网下载安装包
地址https://golang.google.cn/dl/
下载完成后,执行安装文件,一直下一步即可完成安装(安装位置自选)
打开 cmd 执行 go version 查看是否有能查询版本号,如下图。
配置
配置GOPATH
新建一个文件夹作为工作区,位置随意,目录为英文
系统变量中新建一个GOPATH变量,值为上面的新建文件夹地址
因为Go在安装时会分配一个默认工作区,在用户变量中,需要删除

然后挨个确定,进行保存
配置完成后,在新建的文件夹中创建三个文件夹

创建后进入bin文件夹复制地址,在用户环境变量PATH中添加bin文件夹地址


将默认的变量修改为bin目录地址
保存后 go env查看

vs code
编辑器的话,我使用的是vscode
官网下载后自行安装
打开编辑器,点击扩展,下载go语言扩展
想下载中文插件,自行搜索安装
用编辑器打开之前创建的src文件夹,打开后创建文件夹hello,再创建文件main.go

这里还推荐一个插件Tabnine,可以进行自动补全,非常爽
测试
开始编写第一个go程序
package main
import "fmt"
func main() {
fmt.Println("hello GO")
}

写的时候右下角一直弹提示,这些事安装go插件用于扩展代码,下载的时候通常会失败,因为这些包都在外网。这时候就设置GOPROXY(代理)就行
cmd分别执行下面两行命令
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
验证是否配置成功

Windows平台按下Ctrl+Shift+P,Mac平台按Command+Shift+P,这个时候VS Code界面会弹出一个输入框,如下图
我们在这个输入框中输入>go:install,下面会自动搜索相关命令,我们选择
Go:Install/Update Tools这个命令
选中并会回车执行该命令(或者使用鼠标点击该命令)
下载后,成功输出如图:

可以看到这里报个错
进入控制台终端运行命令go mod init demo(项目名称,自行设置)
保存以下代码到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")
}
接下来执行命令,会下载需要用到的包
go mod tidy

还需要了解一些 go mod知识
可以自行百度
接下来就可以写代码了
边栏推荐
- IO stream (file class introduction)
- ETL为什么经常变成ELT甚至LET?
- Ini parsing learning documents
- Basic questions (I)
- Bat 使用细节2
- gazebo/set_ model_ State topic driving UAV model through posture
- Control method of UAV formation
- Ten years' miscellaneous thoughts
- 银河麒麟初体验
- To: k210 realizes face recognition (code interpretation attached)
猜你喜欢

Why does the verification code not refresh when clicked

Usage of case, casez and casex statements in Verilog
![[wechat applet: single or multiple styles, background color, rounded corners]](/img/01/0381915591b0d3c13afbba4d50952d.png)
[wechat applet: single or multiple styles, background color, rounded corners]

First experience of Galaxy Kirin

Unable to access the Internet at win10 /11 hotspot

File Transfer Protocol,FTP文件共享服务器

关于Glide加载图片模糊不清楚

KEIL - 下载调试出现“TRACE HW not present”

InnoDB engine in MySQL

图片。。。。。
随机推荐
1.8 - multi level storage
反編譯正常回編譯出現問題自己解决辦法
1.5 - 逻辑运算
1.8 - 多级存储
Idea run SQL file
Introduction to programming ape (11) -- structure
基础刷题(一)
Detailed description of methods in the interface
1.9 - Cache
Common NPM install errors
Multithreading advanced level
IO stream (file class introduction)
Practice summary of Prometheus project in amu Laboratory
Unable to read file for extraction: gdx64. dll
To: k210 realizes face recognition (code interpretation attached)
Gazebo installation, uninstall and upgrade
Redux source code implementation
Wuenda coursera deep learning course
圖像處理7-圖像增强
Wechat applet mall project