由于此错误,我似乎无法运行我的代码
标准包装中的非标准进口“gopkg.in/olivere/elastic.v5”“goprojects / search”
Main.go位于:C:\ Go \ src \ goprojects \ search \ main.go
GOROOT是C:\ Go
GOPATH是C:\ Go \ src \ goprojects(尝试在此处添加我当前的工作目录\ search,但没有帮助)
当我运行“go get gopkg.in/olivere/elastic.v5”时,我在C:\ Go \ src \ goprojects \ src \ gopkg.in \ olivere \ elastic.v5中获取导入的文件
visual studio代码正在给我这个消息
在以下任何一项中找不到包“go.pkg.in/olivere/elastic.v5”:
C:\ Go \ src \ vendor \ gopkg.in \ olivere \ elastic.v5(供应商树)
C:\ Go \ src \ gopkg.in \ olivere \ elastic.v5(来自$ GOROOT)
C:\ Go \ src \ goprojects \ src \ gopkg.in \ olivere \ elastic.v5(来自$ GOPATH)
我的代码
package main
import (
"fmt"
"net/http"
elastic "gopkg.in/olivere/elastic.v5"
)
func main() {
http.HandleFunc("/search", search)
http.ListenAndServe(":3000", nil)
}
func search(w http.ResponseWriter, r *http.Request) {
searchString := r.URL.Query().Get("q")
fmt.Println("Searching for" + searchString)
// Create a client
client, err := elastic.NewClient()
w.Write([]byte(searchString))
}
答案 0 :(得分:3)
将我的goprojects从我的GoRoot路径移到C:\ goprojects中的一个单独的文件夹中,并用新路径替换了我的GoPath并且它有效。