我可以在我的 Go 程序中直接使用 go-ipfs 吗?
Can I use go-ipfs directly in my Go program?
我通过 go-ifps-api
连接到 IPFS,如本例所示:
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")
...
但是,如果有人下载这样的程序,他们必须安装 go-ipfs
并且还要有 5001 端口可用。我知道 port 可以很灵活,但这样就更复杂了。
我希望用户在不设置 API 服务的情况下透明地连接到 IPFS,因此 IPFS 节点是从 Go 应用程序内部启动和停止的。
是否可以,如果可以,能否举个例子?
是的,您可以将 go-ipfs 用作库。这里有一些例子 https://github.com/ipfs/go-ipfs/tree/90a573354af23e361da87a29f7bafc459967c070/docs/examples。基本上你需要导入 go-ipfs
(和它的一些子包)而不是 go-ipfs-api
.
我通过 go-ifps-api
连接到 IPFS,如本例所示:
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")
...
但是,如果有人下载这样的程序,他们必须安装 go-ipfs
并且还要有 5001 端口可用。我知道 port 可以很灵活,但这样就更复杂了。
我希望用户在不设置 API 服务的情况下透明地连接到 IPFS,因此 IPFS 节点是从 Go 应用程序内部启动和停止的。
是否可以,如果可以,能否举个例子?
是的,您可以将 go-ipfs 用作库。这里有一些例子 https://github.com/ipfs/go-ipfs/tree/90a573354af23e361da87a29f7bafc459967c070/docs/examples。基本上你需要导入 go-ipfs
(和它的一些子包)而不是 go-ipfs-api
.