Go相当陌生,但仍然不知道为什么它不起作用。有一个函数(A)被定义并作为参数传递给另一个函数(B),该函数以完全正确的方式(AFAIK)接收A的参数:

// Function A
func writeToPumps(keys []interface{}, job *health.Job, startTime time.Time) {..}

// Function B
func GenerateDemoData(start time.Time, days int, orgId string, writer func(keys []interface{}, job *health.Job, startTime time.Time)) {...}

//calling Function B with Function A as last argument:
demo.GenerateDemoData(time.Now().AddDate(0, 0, -30), 30, buildDemoData, writeToPumps)

产生:



我怎样才能解决这个问题?

编辑

main.go中导入部分:
import (
"github.com/TykTechnologies/tyk-pump/analytics/demo"
"time"

"os"
"fmt"

"github.com/gocraft/health"
"gopkg.in/vmihailenco/msgpack.v2"

"github.com/TykTechnologies/logrus"
"github.com/TykTechnologies/logrus-prefixed-formatter"
"github.com/TykTechnologies/tyk-pump/analytics"
"github.com/TykTechnologies/tyk-pump/pumps"
"github.com/TykTechnologies/tyk-pump/storage"
"github.com/TykTechnologies/tykcommon-logger"

"gopkg.in/alecthomas/kingpin.v2"
)

其他有用的信息:

GOPATH:/home/nilsnolde/dev/go/uni
项目结构:
../uni/src/
        |
        --tyk-pump/
              |
              --vendor/
                main.go
                ...

最佳答案

您的代码应位于/uni/src/github.com/TykTechnologies/tyk-pump下。既然没有,那么当您的代码内部引用该包层次结构时,它将重新提供您的代码,从而生成重复的导入路径。

因此,解决方法可能只是将/uni/src/tyk-pump移至/uni/src/github.com/TykTechnologies/tyk-pump,然后重新导入所有供应商的软件包。

10-08 07:39