Fork me on github

【go-1】使用VS Code写GO程序

一、安装go

1. 下载:

Downloads - The Go Programming Language

下载的时候选择对应的操作系统的版本,下图为Windows 64位 安装文件:

 

 

 2. 安装

一路点next即可,环境不需要配置,默认给弄好的。

3. 验证

进入cmd或者power shell,或者vscode的终端,输入go

 

 

 二、vscode写一个helloworld

1. 新建go文件(后缀名 .go)

代码:

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

三、安装go插件

1. 安装插件

 

 

 2. 安装环境所需

2.1

vscode打开go文件,提示install,直接install all,等待安装。

2.2

可能大概率会安装失败,到终端修改如下:

go env -w GO111MODULE=on
go env -w GOPROXY=https://proxy.golang.com.cn,direct

2.3

重新打开vscode,按提示install all

四、编译

F5运行,等待结果,正常如下:

 

 【注】可能出现如下情况:

Build Error: go build -o c:\Users\yangqing\Documents\Gitee\go_dev\src__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)

解决方案 - 修改环境:

go env -w GO111MODULE=auto

 

posted @ 2023-02-14 16:45  未配妥剑,已入江湖  阅读(100)  评论(0编辑  收藏  举报