当前位置:网站首页>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知识
可以自行百度
接下来就可以写代码了
边栏推荐
- Notes of the first week of 2021 Chengdu Arts and Sciences cloud computing intensive training class
- JS prototype chain object function relationship
- gazebo/set_ model_ State topic driving UAV model through posture
- Dynamic routing job
- Practice summary of Prometheus project in amu Laboratory
- To: k210 realizes face recognition (code interpretation attached)
- 图片。。。。。
- Numpy中的四个小技巧
- Wechat applet mall project
- 1.9 - Classification of memory
猜你喜欢

C language final experiment report (student achievement management system) source code

与MQTT的初定情缘

IO streams (common streams)

从底层结构开始学习FPGA----RAM IP核及关键参数介绍

判断h5在两端是在微信环境还是企业微信环境

First experience of Galaxy Kirin

Unable to access the Internet at win10 /11 hotspot

原来你是这样的数组,终于学会了

DHCP operation

Introduction to programming ape (11) -- structure
随机推荐
1.2(补充)
Is it safe to open an account online? Can you open an account to speculate on the Internet?
原理:WebMvcConfigurer 与 WebMvcConfigurationSupport避坑指南
As function memo
Pay attention to this live broadcast and learn about the path to achieve the dual carbon goal of the energy industry
Inner member of class 5: inner class
Common address collection
Win10 /11 开热点无法上网问题
程序猿入门攻略(十一)——结构体
Application of redis client list in practice
力扣------替换空格
Go pack and unpack
阿里云买的40G高效云盘挂载只有20G
Ini parsing learning documents
Zibll sub theme v6.4.1wordpress open source download_ Crack the original / use it directly / no tutorial required
C language final experiment report (student achievement management system) source code
Set in set (III)
ES6 arrow function
Gazebo model modification
Cocos studio3.1 installation package win