首页 文章

标准包窗口中的非标准导入

提问于
浏览
-1

由于这个错误,我似乎无法运行我的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))
}

1 回答

  • 2

    将我的goprojects从我的GoRoot路径移到C:\ goprojects中的一个单独的文件夹中,并用新路径替换了我的GoPath并且它有效 .

相关问题