Mac环境下VScode安装Go
![pic](https://raw.githubusercontent.com/CooperXJ/ImageBed/master/img/20200928145142.png)
-
查看当前go的环境变量并根据自己的工程路径对GOPath进行修改
-
我的工程路径为
![pic](https://raw.githubusercontent.com/CooperXJ/ImageBed/master/img/20200928145047.png)
子目录go下的工程路径为
![pic](https://raw.githubusercontent.com/CooperXJ/ImageBed/master/img/20200928145116.png)
-
当我们在src目录下创建main.go文件是会自动的弹出插件的下载提示,此时我们需要先对proxy进行修改(也就是刚刚在上面提到的),根据网站的提示进行修改,修改完之后就可以进行愉快的下载了
-
我们需要在src的根目录下进行mod的创建,也就是go目录下
go mod init mygo
此处一定要记得是在go目录下创建,如果在go的根目录Go下创建的话会有冲突
-
编写launch.json 配置文件(需要根据自己的情况进行配置也就是下面的两个GOPATH)
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${fileDirname}", "env": { "GOPATH": "/Users/cooper/Documents/Code/VScode/Go" }, "args": [], "showLog": true }, { "name": "Test", "type": "go", "request": "launch", "mode": "test", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${fileDirname}", "env": { "GOPATH": "/Users/cooper/Documents/Code/VScode/Go" }, "args": [], "showLog": true } ] }
-
测试代码
package main import "fmt" func main() { fmt.Println("Hello GO") fmt.Println("Hello aaaa") fmt.Println("Hello aaaa") }
-
测试结果:
![pic](https://raw.githubusercontent.com/CooperXJ/ImageBed/master/img/20200928144956.png)