Error "command not found" when I'm using Go IPFS API

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?

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#L141 for what is available

Very thank you! Now, it’s work!

And… one more question: I always need run a daemon if I want send a file to IPFS? In my Go project, it’s not good… We have other solution?

You send the file to your daemon. If the daemon is running other people can access the file. You never send it “to IPFS”, you never store anyone else’s content you didn’t ask for.