vscode cannot import go definition package [can not find package....]

vscode cannot import go definition package [can not find package...]

I am a Java programmer, and I played go on VS recently. How can I say it? The basics are actually similar to Java, nothing more than importing packages. I encountered such a problem in development, I think I can share it

vscoded import custom git package above can’t be found:
Not much nonsense, go straight to the topic, when you complete a series of configurations, run the following code:

package main

import (
	"log"
	"os"

	_ "github.com/goinaction/code/chapter2/sample/matchers"
	"github.com/goinaction/code/chapter2/sample/search"
)

//init 在main之前调用
func init() {
	//将日志输出到标准输出
	log.SetOutput(os.Stdout)
}

//main是整个程序的入口
func main() {
	//使用特定的项做搜索
	search.Run("president")
}

The above calls a run method in a search package, and the import is obviously an external package on github, maybe you will encounter this problem like me
Insert picture description here

The corresponding file cannot be found here. Here, two solutions are summarized:
1. According to the error directory that cannot be found in the appeal, create one directly in the corresponding root or path location, and then put the source code package in (if this method is dependent on Too many packages are difficult to manage, not recommended, troublesome)

2. Pull through the get code
Insert picture description here
Find the corresponding path location, check whether there is a go file, and then pull through the command

 go get -u github.com/goinaction/code/chapter2/sample/matchers

Such as

I
would like to advise a lot of comments in this article
(personal understanding, in fact, many languages ​​have similarities, such as maven in Java, and there are many similarities, sometimes you can't find it, just need to clean up *update)
such as If necessary, please keep the original link for forwarding

Guess you like

Origin blog.csdn.net/MatChen/article/details/110490828