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

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

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))
}
  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失