gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 03:34:48 26 4
gpt4 key购买 nike

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

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

但是,它是一样的,因为我手动将它复制到我所有 Go 包所在的/home/niko/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 这个包是好的?

最佳答案

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 中。当他们出售他们的依赖项时(即:他们将他们的依赖项复制到 vendor 文件夹中)引用: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/尼科/去

我觉得不太好。

如果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

关于go - 不能在 Go 中使用函数作为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46619887/

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