gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 02:29:08 26 4
gpt4 key购买 nike

由于这个错误,我似乎无法运行我的 go 代码

non-standard import "gopkg.in/olivere/elastic.v5" in standard package "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 code 给我这条信息

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)

我的代码

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

最佳答案

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

关于go - 标准包窗口中的非标准导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46140491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com