2
votes

Fairly new to Go, but still no idea why this isn't working. There's a function (A) being defined and passed as argument to another function (B), which takes A's arguments in the exact correct way (AFAIK):

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

That yields:

./main.go:191:56: cannot use writeToPumps (type func([]interface {}, *"tyk-pump/vendor/github.com/gocraft/health".Job, time.Time)) as type func([]interface {}, *"github.com/TykTechnologies/tyk-pump/vendor/github.com/gocraft/health".Job, time.Time) in argument to demo.GenerateDemoData

How can I fix this?

EDIT

Import section in 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"
)

Other useful info:

GOPATH: /home/nilsnolde/dev/go/uni

Project structure:

../uni/src/
        |
        --tyk-pump/
              |
              --vendor/
                main.go
                ...
2
You have a funky import path there: "tyk-pump" isn't a valid import path, but somehow your code thinks that's the import path it's using. This is probably the result of not setting up proper path structure for your project, but it's impossible to fully diagnose without seeing your layout. - Flimzy
Ok, that's the project name, i.e. the repo I'm working on. Can you specify layout? Working with GoLand and I thought I set up everything properly. - nnolde
Well, your project should then live under a path such as "hostname.com/organization/project". But you have two import paths: One "tyk-pump" and the other "github.com/TykTechnologies/tyk-pump". I don't know exactly what you did to get those two, but the first one is wrong. - Flimzy
Thanks @Flimzy, not sure what happened.. See edit. - nnolde
Your last edit indicates the problem. Your code slove live under /uni/src/github.com/TykTechnologies/tyk-pump. Since it doesn't, when your code internally references that package heirarchy, it re-vendors your code, generating duplicate import paths. - Flimzy

2 Answers

3
votes

Your code should live under /uni/src/github.com/TykTechnologies/tyk-pump. Since it doesn't, when your code internally references that package hierarchy, it re-vendors your code, generating duplicate import paths.

So the fix is probably just to move /uni/src/tyk-pump to /uni/src/github.com/TykTechnologies/tyk-pump then re-import all your vendored packages.

2
votes

The file in which function A is defined is likely not the same file where you have B defined. The two files are both importing health, where the definition of health.Job seems to live.

However they seem to be using a different import path, therefore GO thinks that the definition of health.Job isn't the same.

You should check the import statements in both places and make them the same. If they are already the same, there is something in the project setup that needs to be adjusted, but there isn't enough context to figure out what that might be.