Can I use go-ipfs directly in my Go program?

Viewed 1205

I connect to IPFS via go-ifps-api like in this example:

 import api "github.com/ipfs/go-ipfs-api"

 shell := api.NewShell("localhost:5001")
 cid, err := shell.Add(bytes.NewBufferString("Hello world"))
 ...
 err = shell.Get(cid, "hello.txt")
 ...

However, if someone downloads such a program, they have to install go-ipfs and also have the 5001 port free. I understand that port can be flexible, but then it is one more complication.

I would like users to connect to IPFS transparently without setting up an API service, so the IPFS node is started and stopped from inside of a Go application.

Is it possible, and if yes, can you provide an example?

1 Answers
Related