Vscode配置GO环境

下载安装包

安装go软件

下载官网地址

  • https://golang.google.cn/dl/

在这里插入图片描述

双击.msi文件进行安装

在这里插入图片描述

这里更改了一下安装环境D:\Environmet\go

在这里插入图片描述
安装目录如下:
在这里插入图片描述

配置环境变量

检查是否go安装目录下面的bin放进path路径
在这里插入图片描述
go version查看版本
在这里插入图片描述

go env查看环境

GO111MODULE是 go modules 功能的开关。设置为on,表示模块支持,go命令行会使用modules,而不会去GOPATH目录下查找。

set GO111MODULE=on

表示go的代理设置,golang默认的GOPROXY是https://goproxy.io。

set GOPROXY=https://goproxy.cn

Vscode配置

从扩展管理中安装Go插件
在这里插入图片描述
按ctrl+shift+p 调出命令面板,输入go install tools 选Go: Install/Update Tools
或者
新建文件夹根据提示安装
在这里插入图片描述
BUG:VSCODE安装GO插件Faill

Tools environment: GOPATH=C:\Users\admin\go
Installing 1 tool at C:\Users\admin\go\bin in module mode.
  go-outline

Installing github.com/ramya-rao-a/go-outline@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "D:\\Environmet\\go\\bin\\go.exe install -v github.com/ramya-rao-a/go-outline@latest",
 "stdout": "",
 "stderr": "go: github.com/ramya-rao-a/go-outline@latest: module github.com/ramya-rao-a/go-outline: Get \"https://proxy.golang.org/github.com/ramya-rao-a/go-outline/@v/list\": dial tcp 142.251.42.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\n"
}

1 tools failed to install.

go-outline: failed to install go-outline(github.com/ramya-rao-a/go-outline@latest): Error: Command failed: D:\Environmet\go\bin\go.exe install -v github.com/ramya-rao-a/go-outline@latest
go: github.com/ramya-rao-a/go-outline@latest: module github.com/ramya-rao-a/go-outline: Get "https://proxy.golang.org/github.com/ramya-rao-a/go-outline/@v/list": dial tcp 142.251.42.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
# 新版改成如下链接
go env -w GO111MODULE=on
go env -w GOPROXY=https://proxy.golang.com.cn,direct

注意如果Go安装不了goimports库,可以用安装goimports第三方库命令进行安装。

go install golang.org/x/tools/cmd/goimports@latest

在这里插入图片描述
BUG再现

go: go.mod file not found in current directory or any parent directory;
 see ‘go help modules‘

初始化Go moudle,运行下面命令

go mod init xxx //xxx代表文件夹名

在这里插入图片描述

编写Hello Go程序

定义test文件夹,在该文件夹下定义test.go文件。
在这里插入图片描述
码入hello go。

package main

import "fmt"

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

注意:要将程序写成 package main,否则会报以下错误!
在这里插入图片描述

Hello GO运行成功!

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值