【问题标题】:"Command not found" when try send a file to IPFS尝试将文件发送到 IPFS 时出现“找不到命令”
【发布时间】:2018-01-17 00:12:54
【问题描述】:

我想在我的项目中使用 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 库。

如何解决?

【问题讨论】:

    标签: go ipfs


    【解决方案1】:

    错误与各种路径无关。程序正在运行并且它很恐慌,因为您已经要求它在出现错误时这样做:

    mhash, err := shell.AddNoPin(bufferExample)
    if err != nil {
        panic(err) // ends where
    }
    

    错误add: command not found 是由于您的系统无法找到add 命令(错误是http 404)。

    您是否在系统上安装了 IPFS 命令?如果没有,请在执行此操作后尝试。

    【讨论】:

    • 是的,我已经安装了 IPFS 命令。例如,我可以运行守护进程。
    【解决方案2】:

    用户 Magik6k 在another forum 中回答了我的问题:

    您不能使用公共 IPFS 网关添加内容。为此你 需要本地运行的守护进程并将其 API 端点传递给 NewShell (默认为 localhost:5001)。

    公共网关(ipfs.io, localhost:8080) 仅支持有限的 API 子集,见 https://github.com/ipfs/go-ipfs/blob/master/core/commands/root.go#L1412 什么是可用的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-16
      • 2012-02-08
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-22
      • 2019-12-26
      • 1970-01-01
      相关资源
      最近更新 更多