简体   繁体   English

我可以在我的 Go 程序中直接使用 go-ipfs 吗?

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

I connect to IPFS via go-ifps-api like in this example:我通过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")
 ...

However, if someone downloads such a program, they have to install go-ipfs and also have the 5001 port free.但是,如果有人下载了这样的程序,他们必须安装go-ipfs并且还免费提供 5001 端口。 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.我希望用户在不设置 API 服务的情况下透明地连接到 IPFS,因此 IPFS 节点从 Go 应用程序内部启动和停止。

Is it possible, and if yes, can you provide an example?有没有可能,如果有,你能举个例子吗?

Yes, you can use go-ipfs as a library.是的,您可以将 go-ipfs 用作库。 There are some examples here https://github.com/ipfs/go-ipfs/tree/90a573354af23e361da87a29f7bafc459967c070/docs/examples .这里有一些例子https://github.com/ipfs/go-ipfs/tree/90a573354af23e361da87a29f7bafc459967c070/docs/examples Basically you need to import go-ipfs (and some of its subpackages) instead of go-ipfs-api .基本上你需要导入go-ipfs (及其一些子包)而不是go-ipfs-api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM