目录
- 安装
- 环境变量配置
- 运行helloword
- 设置代理
- vscode编辑器调试golang
一种语言会老吗?
Objective-CSwiftc语言golang
他们是像似一种血缘的关系,一出生就带有了某种的相似性。
c语言golanggolang
安装
到官方的下载地址下进行下载:点这里。
windows
一路安装到底就对了。
选择安装的路径:
C:\Program Files\Go
golang
环境变量配置
- 环境变量path
pathgolang
确实,安装程序很聪明,已经把路径给安装上了。
- GOPATH
GolangProjectsgolang
GolangProjects
bin:go installpkg:go installsrc
GOPATH
- GOBIN
GOBINC:\work\GolangProjects\bin
- GOROOT
GOROOTC:\work\GolangProjects\bin
go
运行helloword
C:\work\GolangProjects\hellomain.go
package main import "fmt" func main() { fmt.Println("hello world!") }
运行代码:
C:\work\GolangProjects\hello>go run main.go
结果 如下:
hello world!
设置代理
有些时候在下载包的时候很慢,如下的命令,开始提高速度:
C:\Users\Administrator>go env -w GO111MODULE=on C:\Users\Administrator>go env -w GOPROXY=https://goproxy.cn
vscode编辑器调试golang
vscode
go
go:install/update
go:install/update tools
全选,安装。
提示安装完成。
Tools environment: GOPATH=C:\work\GolangProjects, GOBIN=C:\work\GolangProjects\bin Installing 7 tools at the configured GOBIN: C:\work\GolangProjects\bin in module mode. gotests gomodifytags impl goplay dlv staticcheck gopls Installing [email protected] (C:\work\GolangProjects\bin\gotests.exe) SUCCEEDED Installing [email protected] (C:\work\GolangProjects\bin\gomodifytags.exe) SUCCEEDED Installing [email protected] (C:\work\GolangProjects\bin\impl.exe) SUCCEEDED Installing [email protected] (C:\work\GolangProjects\bin\goplay.exe) SUCCEEDED Installing [email protected] (C:\work\GolangProjects\bin\dlv.exe) SUCCEEDED Installing [email protected] (C:\work\GolangProjects\bin\staticcheck.exe) SUCCEEDED Installing [email protected] (C:\work\GolangProjects\bin\gopls.exe) SUCCEEDED All tools successfully installed. You are ready to Go. :)
vscodeC:\work\GolangProjects\helloF5launche.jsonlaunche.json
F5
Build Error: go build -o c:\work\GolangProjects\hello\__debug_bin.exe -gcflags all=-N -l .
go: go.mod file not found in current directory or any parent directory; see 'go help modules' (exit status 1)
mod
什么也没有,以后我们再来聊聊,这个文件的作用:
module hellogo go 1.19
F5