英文:
Can't execute program in the older Go version
问题
我正在尝试构建在GitHub上找到的程序(https://github.com/ginuerzh/gimme-bitcoin-address)。
我已经使用Go语言编程半年了,但我从未遇到过程序缺少"go.mod"文件或主函数的情况。
构建指令看起来像这样,但是如果没有"go.mod"文件,就无法构建,所以我使用go mod init ...
命令,但这不是我在这里要问的问题。
$ git clone git://github.com/vsergeev/gimme-bitcoin-address.git
$ cd gimme-bitcoin-address
$ go get code.google.com/p/go.crypto/ripemd160
$ go build
go build
当然不会构建任何东西。
值得注意的是go get ...
已经过时了,你需要导入"golang.org/x/crypto/ripemd160"
。
项目结构如下:
gimme-bitcoin-address/
|-- LICENSE
|-- README
|-- gimme-bitcoin-address.go
|-- gimme-bitcoin-address_test.go
正如你所看到的,没有main.go文件,但这并不是真正的问题。
除了xx_test.go之外,只有一个可构建的文件gimme-bitcoin-address.go,让我们来看看代码。
与package main
不同,这里是package btcaddr
,最接近主函数的函数是func _main
总结一下,我的问题是在克隆存储库后如何运行这个程序,或者如何修复它?我不太清楚,也许这是一些老式的语法,但是函数_main
没有被任何地方调用。
这可能是一个相当新手的问题,但我无法解决它。我希望也许有人可以帮助我。
英文:
I'm trying to build program found on github.(https://github.com/ginuerzh/gimme-bitcoin-address)
I have been programming in golang for half a year, but I have never encountered a situation where the program lacks the "go.mod" file or the main function.
Build instruction looks like this, but you can't build without go.mod file, so I use go mod init ...
, but it is not my question here.
$ git clone git://github.com/vsergeev/gimme-bitcoin-address.git
$ cd gimme-bitcoin-address
$ go get code.google.com/p/go.crypto/ripemd160
$ go build
go build
isn't building anything ofcourse
Worth to notice is that go get ...
is outdated, and you have to import "golang.org/x/crypto/ripemd160"
Project structure looks like this:
gimme-bitcoin-address/
|-- LICENSE
|-- README
|-- gimme-bitcoin-address.go
|-- gimme-bitcoin-address_test.go
And, as you see there's no main.go file, but as before this is not real problem.
Only one able-to-build file (except the xx_test.go) is gimme-bitcoin-address.go, let's look at the code.
Instead of package main
, there's package btcaddr
, what else the function that is closest to the main function is func _main
To sum this all up - my question is how can I run this program, after cloning repository, or how to fix it? I dont't really know but, maybe this is some old-fashioned syntax, but function _main
is not called anywhere.
It's probably quite newbie question, but I can't handle it. I hope maybe someone would help me.
答案1
得分: 1
如果你只是想构建这个项目,以下步骤应该可以工作:
$ cd /tmp
$ go version
go version go1.18.5 linux/amd64
$ git clone https://github.com/vsergeev/gimme-bitcoin-address.git
正在克隆到 'gimme-bitcoin-address'...
远程: 正在枚举对象:261,完成。
远程: 总共 261 (delta 0),复用 0 (delta 0),完成。
接收对象: 100% (261/261),62.36 KiB | 1.02 MiB/s, 完成。
处理 delta: 100% (142/142),完成。
$ cd gimme-bitcoin-address/
$ ls
ChangeLog.md LICENSE README.md btckey main.go
$ go mod init testing
go: 正在创建新的 go.mod 文件:module testing
go: 要添加模块要求和校验和:
go mod tidy
$ go mod tidy
go: 正在查找包 golang.org/x/crypto/ripemd160 的模块
go: 正在查找包 github.com/vsergeev/btckeygenie/btckey 的模块
go: 正在下载 golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d
go: 正在下载 github.com/vsergeev/btckeygenie v1.1.0
go: 在 github.com/vsergeev/btckeygenie v1.1.0 中找到 github.com/vsergeev/btckeygenie/btckey
go: 在 golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d 中找到 golang.org/x/crypto/ripemd160
$ go build
$ ls -la
总用量 2124
drwxrwxrwx 1 ubuntu ubuntu 512 8月 26 16:08 .
drwxrwxrwx 1 ubuntu ubuntu 512 8月 26 16:07 ..
drwxrwxrwx 1 ubuntu ubuntu 512 8月 26 16:08 .git
-rwxrwxrwx 1 ubuntu ubuntu 45 8月 26 16:07 ChangeLog.md
-rwxrwxrwx 1 ubuntu ubuntu 1088 8月 26 16:07 LICENSE
-rwxrwxrwx 1 ubuntu ubuntu 3616 8月 26 16:07 README.md
drwxrwxrwx 1 ubuntu ubuntu 512 8月 26 16:07 btckey
-rwxrwxrwx 1 ubuntu ubuntu 131 8月 26 16:08 go.mod
-rwxrwxrwx 1 ubuntu ubuntu 394 8月 26 16:08 go.sum
-rwxrwxrwx 1 ubuntu ubuntu 2860 8月 26 16:07 main.go
-rwxrwxrwx 1 ubuntu ubuntu 2158646 8月 26 16:08 testing
这是在使用Go 1.18.5的Ubuntu 20.04 Windows子系统环境中进行的操作。
英文:
If you are just trying to build the project, the following should work:
$ cd /tmp
$ go version
go version go1.18.5 linux/amd64
$ git clone https://github.com/vsergeev/gimme-bitcoin-address.git
Cloning into 'gimme-bitcoin-address'...
remote: Enumerating objects: 261, done.
remote: Total 261 (delta 0), reused 0 (delta 0), pack-reused 261
Receiving objects: 100% (261/261), 62.36 KiB | 1.02 MiB/s, done.
Resolving deltas: 100% (142/142), done.
$ cd gimme-bitcoin-address/
$ ls
ChangeLog.md LICENSE README.md btckey main.go
$ go mod init testing
go: creating new go.mod: module testing
go: to add module requirements and sums:
go mod tidy
$ go mod tidy
go: finding module for package golang.org/x/crypto/ripemd160
go: finding module for package github.com/vsergeev/btckeygenie/btckey
go: downloading golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d
go: downloading github.com/vsergeev/btckeygenie v1.1.0
go: found github.com/vsergeev/btckeygenie/btckey in github.com/vsergeev/btckeygenie v1.1.0
go: found golang.org/x/crypto/ripemd160 in golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d
$ go build
$ ls -la
total 2124
drwxrwxrwx 1 ubuntu ubuntu 512 Aug 26 16:08 .
drwxrwxrwx 1 ubuntu ubuntu 512 Aug 26 16:07 ..
drwxrwxrwx 1 ubuntu ubuntu 512 Aug 26 16:08 .git
-rwxrwxrwx 1 ubuntu ubuntu 45 Aug 26 16:07 ChangeLog.md
-rwxrwxrwx 1 ubuntu ubuntu 1088 Aug 26 16:07 LICENSE
-rwxrwxrwx 1 ubuntu ubuntu 3616 Aug 26 16:07 README.md
drwxrwxrwx 1 ubuntu ubuntu 512 Aug 26 16:07 btckey
-rwxrwxrwx 1 ubuntu ubuntu 131 Aug 26 16:08 go.mod
-rwxrwxrwx 1 ubuntu ubuntu 394 Aug 26 16:08 go.sum
-rwxrwxrwx 1 ubuntu ubuntu 2860 Aug 26 16:07 main.go
-rwxrwxrwx 1 ubuntu ubuntu 2158646 Aug 26 16:08 testing
This is from an Ubuntu 20.04 Windows Subsystem for Linux environment using Go 1.18.5.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论