尝试将文件发送到IPFS时出现“命令未找到”的错误。

huangapple go评论81阅读模式
英文:

"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.

huangapple
  • 本文由 发表于 2017年8月9日 16:07:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/45585013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定