当前位置:网站首页>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": [
]
}
边栏推荐
- 2.5 Quick Sort
- (Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
- 全流程调度——Azkaban入门与进阶
- C# One Week Introductory "C# - Classes and Objects" Day Six
- 小程序使用npm包定制全局样式
- The Azure developer news 丨 memorabilia in July
- Simulation Problem (Part 1)
- WPF introduces ttf icon file usage record
- 【MySQL系列】-B+树索引和HASH索引有什么区别
- [Android development] Splash interface / user agreement and privacy policy pop-up window / interface development
猜你喜欢
Compound Types--references, pointers
[MRCTF2020]Hello_ misc
Protobuf compound data types, speaking, reading and writing
See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
Unity beginner 5 cameras follow, border control and simple particle control (2 d)
Alibaba Cloud's EasyNLP Chinese text image generation model takes you to become an artist in seconds
IGBT wafers used in photovoltaic inverters
DAY17, CSRF vulnerability
七、自定义配置
Go study notes (84) - Go project directory structure
随机推荐
Predictive maintenance scheduling of multiple power equipment based on data-driven fault prediction
Solve the go environment can not compile exe
Dynamically bind href url
Perspective transformation matrix of image perspective correction should be matrix (single)/findHomography with getPerspectiveTransformd difference
Six, read application configuration + log configuration
Unity beginner 5 cameras follow, border control and simple particle control (2 d)
Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
Boss Rush (two-point answer + DP)
Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction
Some understanding of YOLOv7
A must see for software testers!Database knowledge MySQL query statement Daquan
webService接口
2.6 Radix sort (bucket sort)
文件系统二
字符串问题(下)
[MRCTF2020]Hello_ misc
Catch That Cow(详解)
1315_Use the LOOPBACK simulation mode to test whether the pyserial installation is successful
Discourse 自定义头部链接(Custom Header Links)
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering