英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论