0

git.domain.com/a/b/main.go:

import (
    "github.com/spf13/cobra"

    "git.domain.com/x/y/tlsgenerate"
)

func main() {
    rootCmd.AddCommand(tlsgenerate.CobraCommand)
}

git.domain.com/x/y/tlsgenerate/cmd.go:

package tlsgenerate

import (
    "github.com/spf13/cobra"
)

var CobraCommand = &cobra.Command{

}

and gometalinter said that:

warning: cannot use tlsgenerate.CobraCommand (variable of type *git.domain.com/x/y/vendor/github.com/spf13/cobra.Command) as *git.domain.com/a/b/vendor/github.com/spf13/cobra.Command value in argument to rootCmd.AddCommand (megacheck)

We use dep to manage dependency. And github.com/spf13/cobra exist in both a/b/vendor and x/y/vendor.

How can I fix this?

quanta
  • 3,960
  • 4
  • 40
  • 75
  • 2
    Dep should "flatten" vendor directories to avoid precisely this problem. There should only be a single directory called vendor in the project tree. Is that not the case for you? – Peter Apr 06 '18 at 10:50
  • If I remove vendor in git.domain.com/x/y, then I got "warning: unused struct field cannot use tlsgenerate.CobraCommand (variable of type *invalid type) as *git.domain.com/a/b/vendor/github.com/spf13/cobra.Command value in argument to rootCmd.AddCommand (structcheck)". What's wrong? – quanta Apr 06 '18 at 12:07
  • 1
    Your single vendor directory should be at the top level of your project, or not all packages will use the same import. – JimB Apr 06 '18 at 13:24

0 Answers0