使用VSC:无法导入errors库

huangapple go评论86阅读模式
英文:

Go with VSC: Unable to import errors library

问题

我在VSC中打开了一个go文件,并且我看到已经导入了一些基本的go库:

import (
	"flag"
	"fmt"
	"time"

但是当我尝试添加"errors"时,VSC不允许它,并且将其从导入中删除。

我理解errors也是像fmt等一样的基本go库。

那么为什么对我不起作用呢?

英文:

I have a go file opened in VSC, and I see some basic go libs imported already:

import (
	"flag"
	"fmt"
	"time"

But when I try to add "errors", VSC doesn't allow it, and just removes it from the imports.

I understand errors too is one of the basic go libs just like fmt etc.

So why doesnt it work for me?

答案1

得分: 1

Go不允许未使用的导入语句存在于源代码中。

默认情况下,VSCode使用gofmt在保存时格式化Go源代码,并在可用时使用goimports作为替代。除了所有gofmt的功能外,goimports的一个亮点是它会验证和组织你的导入语句,这对于减少编译器错误非常有帮助。

英文:

Go does not allow an unused import to remain in your source code.

VSCode by default uses gofmt to format Go sources on save, and goimports as a substitute if it's available. In addition to all gofmt features, a highlight of goimports is that it validates and organizes your imports, which is quite helpful for reducing compiler errors.

huangapple
  • 本文由 发表于 2023年5月1日 22:57:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76147908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定