https://golang.google.cn/dl/
按步骤安装即可,安装完成后需要设置Windows环境变量
配置好,做个测试
PS E:\Teld\01Code\Personal\golang> go env -w GO111MODULE=on warning: GOPATH set to GOROOT (E:\Program Files\Go\) has no effect PS E:\Teld\01Code\Personal\golang> go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/ warning: GOPATH set to GOROOT (E:\Program Files\Go\) has no effect配置好两个变量后,重新打开VSCode,点击右下方的install all重新安装,或者,在vscode中使用Ctrl+Shift+P,输入>go:install,下面会自动搜索相关命令,我们选择Go:Install/Update Tools这个命令,选中所有插件,点击确定进行安装。
安装Go插件后,继续安装VSCode Go 扩展
package main // 堆代码 duidaima.com import ( "fmt" "net/http" ) func main() { fmt.Println("Server is running on port 8080") http.Handle("/", http.FileServer(http.Dir("."))) http.Handle("/Test", Test()) http.ListenAndServe(":8080", nil) } func Test() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello World") }) }终端中执行go mod init golang