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