不能在Go中使用函数作为类型

时间:2017-10-07 12:01:11

标签: go

我正在尝试从源代码运行以太坊(我想用调试器跟踪执行)并且我在编译时遇到问题。这是我得到的错误:

[niko@localhost sources]$  go run github.com/ethereum/go-ethereum/cmd/geth/main.go github.com/ethereum/go-ethereum/cmd/geth/config.go github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go github.com/ethereum/go-ethereum/cmd/geth/monitorcmd.go github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go gopkg.in/urfave/cli.v1  --verbosity 5 --ipcdisable --port 40401 --rpc --rpcport 9101 --pprof --datadir=/home/niko/saved-niko-home/myeth/ --networkid=15 console 
# command-line-arguments
github.com/ethereum/go-ethereum/cmd/geth/config.go:42: cannot use dumpConfig (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:43: cannot use initGenesis (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:60: cannot use importChain (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:78: cannot use exportChain (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:95: cannot use removeDB (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:108: cannot use dump (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/monitorcmd.go:52: cannot use monitor (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:50: cannot use importWallet (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:96: cannot use accountList (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:107: cannot use accountCreate (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:107: too many errors
[niko@localhost sources]$ 
[niko@localhost sources]$ echo $GOPATH
/home/niko/sources/github.com/ethereum/go-ethereum/build/_workspace/:/home/niko/sources/github.com/ethereum/go-ethereum/vendor:/home/niko/go
[niko@localhost sources]$ 

你可以看到它抱怨:

func(*"gopkg.in/urfave/cli.v1".Context)

与:

不同
func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) 

然而,它是相同的,因为我手动将其复制到/ home / niko / go所有Go包所在的位置:

[niko@localhost sources]$ find /home/niko/go -iname "*cli.v1*"
/home/niko/go/src/gopkg.in/urfave/cli.v1
/home/niko/go/pkg/linux_amd64/gopkg.in/urfave/cli.v1.a
[niko@localhost sources]$ 

它在我的GOPATH中

那么,我该如何解决这个错误,如何告诉Go这个包是好的呢?

1 个答案:

答案 0 :(得分:1)

github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1

gopkg.in/urfave/cli.v1

是不同的导入路径包,无论内容如何,​​都被认为是不同的。

这里的问题是你的程序以某种方式从不同的位置加载两次,导致你提供的那种错误信息。

我对你使用的go run命令行不太清楚,我宁愿这样做,

go run github.com/ethereum/go-ethereum/cmd/geth/*go --verbosity 5 --ipcdisable --port 40401 --rpc --rpcport 9101 --pprof --datadir=/home/niko/saved-niko-home/myeth/ --networkid=15 console

除非您想破解以太坊,否则我认为没有理由将其依赖项复制到您的gopath。 当他们出售他们的依赖关系(IE:他们将他们的依赖关系复制到vendor文件夹中)ref:https://github.com/ethereum/go-ethereum/tree/master/vendor你真的应该使用它们。

关于你的gopath

/home/niko/sources/github.com/ethereum/go-ethereum/build/_workspace/:/home/niko/sources/github.com/ethereum/go-ethereum/vendor:/home/niko/go

对我来说看起来不太好。

如果是GOPATH=/home/niko/sources/,那么,

tree $GOPATH -L 1
/home/niko/sources/
├── bin
├── pkg
└── src

3 directories, 0 files

ls -al $GOPATH/src/github.com/ethereum/go-ethereum应该是正确的。

另见go env