由于这个错误,我似乎无法运行我的go代码
标准包“goprojects / search”中的非标准导入“gopkg.in/olivere/elastic.v5”
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中获取导入的文件
视觉工作室代码给了我这个消息
在以下任何一个中找不到包“go.pkg.in/olivere/elastic.v5”:C:\ Go \ src \ vendor \ gopkg.in \ olivere \ elastic.v5(vendor tree)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))
}