我遇到了可能是 Gopls 语言服务器问题:在 VSCode 中使用带有 Go 扩展的 Go 模块时,我的所有外部包导入语句都被标记为不正确。这正是我到目前为止所做的:
在我的 GOPATH/src/github.com/Kozie1337/projectname 中:
go mod init github.com/Kozie1337/projectnamego get -u github.com/gorilla/muxgo.main 里面:
package main
import (
"log"
"net/http"
"github.com/gorilla/mux" // This is being marked as wrong with the err. msg. down below
)
func main() {
r := mux.NewRouter() // This actually works, even though the go linter says that mux isn't imported
http.ListenAndServe(":9000", r)) // server starts too with mux routes
}
[...]
Run Code Online (Sandbox Code Playgroud)
将鼠标悬停在github.com/gorilla/mux导入语句上时,出现错误:
could …Run Code Online (Sandbox Code Playgroud)