Home >Backend Development >Golang >Using VSC: Unable to import error library

Using VSC: Unable to import error library

王林
王林forward
2024-02-09 09:06:29689browse

使用 VSC:无法导入错误库

php Xiaobian Xigua introduces you to a common problem, that is, when using VSC (Visual Studio Code), you encounter the situation of being unable to import the wrong library. This kind of problem often occurs during the development process and brings some trouble to developers. This article will explain how to solve this problem and help you with your coding work smoothly.

Question content

I opened a go file in vsc, and I saw that some basic go libraries have been imported:

import (
    "flag"
    "fmt"
    "time"

But when I try to add "error" vsc doesn't allow it and just removes it from the import.

I also understand that error is one of the basic go libraries, like fmt etc.

Then why doesn't it work for me?

Workaround

Go does not allow unused imports to remain in the source code.

VSCode uses gofmt by default to format Go source code on save, and goimports as an alternative if available. In addition to all the features of gofmt, a highlight of goimports is that it can validate and organize your imports, which is very helpful for reducing compiler errors.

The above is the detailed content of Using VSC: Unable to import error library. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete
Previous article:What is ^0 in golang?Next article:What is ^0 in golang?