英文:
"Command not found" when try send a file to IPFS
问题
我想在我的项目中使用IPFS,所以我正在学习Go IPFS API。然后,我写了这段非常简单的代码:
package main
import (
"fmt"
"bytes"
sh "github.com/ipfs/go-ipfs-api"
)
func main() {
shell := sh.NewShell("https://ipfs.io")
bufferExample := bytes.NewBufferString("Hello IPFS Shell tests")
mhash, err := shell.AddNoPin(bufferExample)
if err != nil {
panic(err) // ends where
}
fmt.Println(mhash)
}
但是我收到了错误消息 panic: add: command not found
,我不明白为什么会出现这个错误。我已经在我的计算机上安装了IPFS(例如,我可以运行守护进程)。我还安装了带有开发依赖的Go IPFS库。
如何修复这个问题?
英文:
I'm want to use IPFS in my project, then, I'm studying about Go IPFS API.
Then, I wrote this very simple code:
package main
import (
"fmt"
"bytes"
sh "github.com/ipfs/go-ipfs-api"
)
func main() {
shell := sh.NewShell("https://ipfs.io")
bufferExample := bytes.NewBufferString("Hello IPFS Shell tests")
mhash, err := shell.AddNoPin(bufferExample)
if err != nil {
panic(err) // ends where
}
fmt.Println(mhash)
}
But I receive the error panic: add: command not found
, and I don't understand why. I already have IPFS in my computer (I can run the deamon, for example). I also installed the Go IPFS library with development dependencies.
How to fix it?
答案1
得分: 3
用户Magik6k在另一个论坛中回答了我的问题:
> 你不能使用公共IPFS网关添加内容。为此,你需要运行本地守护进程,并将其API端点传递给NewShell(默认为localhost:5001)。
> 公共网关(ipfs.io、localhost:8080)仅支持有限的API子集,请参阅https://github.com/ipfs/go-ipfs/blob/master/core/commands/root.go#L1412,了解可用的功能。
英文:
User Magik6k answered my question in another forum:
> You can't use the public IPFS gateway to add content. For this you
> need locally running daemon and pass it's API endpoint to NewShell
> (localhost:5001 by default).
>
> Public gateways(ipfs.io, localhost:8080) only support a limited API
> subset, see
> https://github.com/ipfs/go-ipfs/blob/master/core/commands/root.go#L1412
> for what is available
答案2
得分: 2
错误与各个路径无关。程序正在运行,但由于你在出现错误时要求它发生恐慌:
mhash, err := shell.AddNoPin(bufferExample)
if err != nil {
panic(err) // 结束位置
}
错误add: command not found
是因为你的系统无法找到add
命令(错误是一个http 404)。
你是否在系统上安装了IPFS命令?如果没有,请在安装后再尝试。
英文:
The error has nothing to do with the various paths. The program is running and it's panicking because you have asked it to in case of an error:
mhash, err := shell.AddNoPin(bufferExample)
if err != nil {
panic(err) // ends where
}
The error add: command not found
is a result of your system not being able to locate the add
command (error is an http 404).
Have you installed IPFS command on your system? If not, try after doing that.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论