当前位置:网站首页>GO语言学习笔记一
GO语言学习笔记一
2022-07-30 04:45:00 【N. LAWLIET】
通过算法学习go
首先go语言环境安装
进入goLang官网https://golang.google.cn/dl/
我下载的是go1.15.15.windows-amd64.msi版本
下载好之后开始安装,它会自动配置环境变量,然后 cmd查看执行go version命令查看是否安装成功。安装好go之后,安装vscode从官网下载安装就好。
然后新建一个goPath文件夹,在这个文件夹下再分别新建src、pkg和bin三个文件夹这个文件夹就是go执行路径,然后编辑环境变量,在系统环境变量中新建GOPATH然后把goPath的路径放到当中,以后再新建go执行目录就用,;间隔。再将%GOPATH%放在Path中。
然后配置vscode setting.json(位置在文件->首选项->设置->右上角图标打开设置)
{
"go.buildOnSave": "workspace",
"go.lintOnSave": "package",
"go.vetOnSave": "package",
"go.buildTags": "",
"go.buildFlags": [],
"go.lintFlags": [],
"go.vetFlags": [],
"go.coverOnSave": false,
"go.useCodeSnippetsOnFunctionSuggest": false,
"go.formatOnSave": true,
"go.formatTool": "goreturns",
"go.goroot": "D:\\Go",
"go.gopath": "D:\\GoPath",
"go.gocodeAutoBuild": false,
"workbench.iconTheme": "vscode-icons",
"gopls": {
"experimentalWorkspaceModule": true
},
"go.toolsManagement.autoUpdate": true,
"window.zoomLevel": -1,
"terminal.integrated.sendKeybindingsToShell": true
}这里把go.goroot改成自己go安装位置,go.gopath改成go执行文件位置。
配置好之后安装vscode中的god的扩展

安装好之后,新建一个go文件,vscode会提示你安装一些插件,点击all install。
这里可能安装不会成功,如果安装失败 ,需要进入cmd执行
go env -w GO111MODULE=on
go env -w GOPROXY=https://proxy.golang.com.cn,direct
然后执行go env 查看更改是否成功,然后再回去执行 all install ,如果还失败需要手动安装
- 在
%GOPATH%\src\目录下,建立路径golang.org\x - 进入到
%GOPATH%\src\golang.org\x,下载需要工具的源码git clone https://github.com/golang/tools.git tools - clone完成后,会生成一个tools文件夹,这样工具所需要的源码已经准备好了
- 进入到
%GOPATH%下,执行 go install github.com/ramya-rao-a/go-outline go install github.com/acroca/go-symbols go install golang.org/x/tools/cmd/guru go install golang.org/x/tools/cmd/gorename go install github.com/rogpeppe/godef go install github.com/sqs/goreturns go install github.com/cweill/gotests/gotests- 单独处理golint,golint的源码位于
https://github.com/golang/lint,进入%GOPATH%\src\golang.org\x后执行git clone https://github.com/golang/lint下载golint需要的源码 - 进入到
%GOPATH%下,执行go install github.com/golang/lint/golint
此时基本大功告成,有可能gopls安装回失败
同样进入%GOPATH%下执行go install golang.org/x/tools/cmd/gopls
然后在src新建一个main文件夹再执行按住shift点击右键进入PowerShell执行go mod init main 命令,再执行 go build
此时go语言环境搭建完成。
最后如果想vscode正常运行还需要配置lang.json(运行->添加配置)根据自己的服务器和需要进行配置
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${fileDirname}",
"env": { //环境变量
"GOPATH":"D:/goPath",
"GOOS":"windows" //要编译成win
},
"args": [],
"showLog": true,
"configurations": [
]
}边栏推荐
- Recursive Optimization of Fibonacci Sequences "Memo Recursion"
- SVN View Username and Password
- Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
- Dynamic Programming Problems (End)
- 四、Web开发
- 【线性表】- LeetCode力扣三道练习题详解
- Repetition XXL - JOB scheduling center background arbitrary command execution
- 六、读取应用配置+日志配置
- VisualStudio2022本地调试进入特别慢问题解决
- Weight line segment tree + line segment tree split/merge + CF1659D
猜你喜欢

unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)

Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
![handler+message [message mechanism]](/img/4b/981d5eb2f1afc98a4ceab38c505325.png)
handler+message [message mechanism]

cnpm installation steps
![[C language] Program environment and preprocessing](/img/d2/a0437da7d651e755951dd2a15827cf.png)
[C language] Program environment and preprocessing

Discourse Custom Header Links

05 Detailed explanation of the global configuration file application.properties

MYSQL unique constraint

Web page element parsing a tag

Predictive maintenance scheduling of multiple power equipment based on data-driven fault prediction
随机推荐
Double pointer problem (middle)
String Problem (Part 1)
Perspective transformation matrix of image perspective correction should be matrix (single)/findHomography with getPerspectiveTransformd difference
Code readability, pre-checks, comments and summaries
深圳见!云原生加速应用构建专场:来看云原生 FinOps、SRE、高性能计算场景最佳实践
Mini Program wx.miniProgram.navigateTo jump address cannot be tabbar address
WPF introduces ttf icon file usage record
Chapter8 支持向量机
Weight line segment tree + line segment tree split/merge + CF1659D
(RCE) Remote Code/Command Execution Vulnerability Vulnerability Exercise
[Redis Master Cultivation Road] Jedis - the basic use of Jedis
error: The following untracked working tree files would be overwritten by
LeetCode Algorithm 2326. Spiral Matrix IV
【线性表】- LeetCode力扣三道练习题详解
Solve the go environment can not compile exe
22. Why do you need a message queue?What are the advantages of using the message queue?
三、依赖配置管理
如何与墨西哥大众VW Mexico建立EDI连接
Golang eight-legged text finishing (continuous handling)
Small program npm package--API Promise