dongyuduan1890
2017-09-10 12:01
浏览 34
已采纳

在标准包装窗口中非标准进口

I can't seem to run my go code because of this error

non-standard import "gopkg.in/olivere/elastic.v5" in standard package "goprojects/search"

Main.go is located at: C:\Go\src\goprojects\search\main.go

GOROOT is C:\Go

GOPATH is C:\Go\src\goprojects (tried adding my current working directory here \search, but didnt help)

when I run "go get gopkg.in/olivere/elastic.v5" I get the imported files in C:\Go\src\goprojects\src\gopkg.in\olivere\elastic.v5

visual studio code is giving me this message

cannot find package "go.pkg.in/olivere/elastic.v5" in any of:

C:\Go\src\vendor\gopkg.in\olivere\elastic.v5 (vendor tree)

C:\Go\src\gopkg.in\olivere\elastic.v5 (from $GOROOT)

C:\Go\src\goprojects\src\gopkg.in\olivere\elastic.v5 (from $GOPATH)

my code

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))
}

图片转代码服务由CSDN问答提供 功能建议

由于此错误,我似乎无法运行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中导入的文件

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) \ n

C:\ Go \ src \ goprojects \ src \ gopkg.in \ olivere \ elastic.v5(来自$ GOPATH)

我的代码

 <代码>点 ackage main 
 
import(
“ fmt” 
“ net / http” 
 
弹性“ 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(“正在搜索” + searchString)
 
 //创建一个客户端
客户端,错误:= elastic.NewClient()
 
  w.Write([] byte(searchString))
} 
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dourang6858 2017-09-10 12:20
    已采纳

    moved my goprojects out of my GoRoot path and into a separate folder in C:\goprojects and replaced my GoPath with the new path and it worked.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题