-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using IPFS as a library (not a as deamon) #3060
Comments
You can avoid using the commands lib entirely, For example, import (
"os"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix"
)
func AddFile(ipfs *core.IpfsNode, file string) (string, error) {
fi, err := os.Open(file)
if err != nil {
return "", err
}
return coreunix.Add(ipfs, fi)
} You can also get a little more integrated and use the Also, let me know of any other commands you want to use, the more popular of the 'commands' will have parallel bits of code under |
Yeah, sorry, that part of the code is a bit of a quagmire. it's very complicated. The As a library, you can do without much of the commands, and call the ipfs node library directly. But problems are:
I think for now we can do two things:
But long term, let's finish the core-ipfs-interface and levelup go-ipfs and go-ipfs-api with it. |
Note: for each command line command, the actual code it executes will be in the relevant run function. So for |
You are using it correctly as far as I can see but we are working on something that will make your life much easier. It is interface-ipfs-core (#2876) which defines simple and small API for interfacing go-ipfs directly, it would work perfectly for using go-ipfs as library, and we also plan to create bindings for it so it can be used when go-ipfs in different process. We are currently finishing work on 0.4.4 release (this is the reason it hasn't been merged for a long time), but it is important to point out that the interface-ipfs-core isn't finished in go. Bad news is that, in next few months we will be focusing on implementing IPLD into IPFS and we won't have much time to finish it. You could either try working on it or just interface go-ipfs directly. Best way to contact us directly is #ipfs@freenode. |
It's still great to ask these questions here-- for others to find. |
Thanks all, that's very helpful. @whyrusleeping Stupid question, what's the easiest way to properly initialise a working |
|
We probably want a mixture of full processes and a bunch in one single process. For example, three physical computers on three continents, each with 10 processes, and each process with 10 nodes. |
@duosearch thats something I want too! My goal was to enable |
Can we try and transform some of this knowledge into a doc somewhere? either in the docs folder or in the faq? |
Yes. I'll work on this. |
Pointing to the IPFS Core API milestone because it's relevant here, and I'm filling it in right now. |
I'd also love to use ipfs as a library in my app. Is there a standard way of doing this? |
I think the Core API is ultimately intended to become the "standard way". At the moment you can interact with IPFS in a number of ways:
|
This is a simple way to use embed ipfs within your go app: http://ipfs.git.sexy/sketches/minimal_ipfs_node.html |
@whyrusleeping thanks! |
The dependency that Are there plans to make it simple to integrate |
@arunthampi |
@arunthampi you also might find @karalabe's fork interesting: https://github.com/ipsn/go-ipfs |
For anyone having issues using @karalabe fork and Go 1.11 modules set your The only bad side is that using go-libp2p-crypto will gause |
Trying to run https://github.com/ipfs/go-ipfs/tree/master/docs/examples/go-ipfs-as-a-library, I am getting
What am I missing? |
@probonopd it looks like you're running an old version of Go. Try using Go 1.13. |
Thanks @aschmahmann. "Old", was using 1.12.
|
Go 1.12 would have worked but you need to export Now you just have a problem with your go install (possibly because you have go 1.12 and 1.13). You may want to look at https://golang.org/doc/install#extra_versions. |
This whole |
Thanks @aschmahmann and @Stebalien, it is working for me now 👍 How can I achieve the equivalent of https://github.com/ipfs/go-ipfs/tree/master/docs/examples/go-ipfs-as-a-library |
@probonopd there is a pattern used throughout the ipfs (and libp2p) codebases which looks like https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md. You can see that https://github.com/ipfs/go-ipfs/blob/3a793a4cc6caee145c0d5a9aec4c6aa6444cbeb8/docs/examples/go-ipfs-as-a-library/main.go#L240 adds a file. However, you can also pass an arbitrary number of Looking around in that package we see that P.S. You're probably better off asking questions like this on discuss.ipfs.io or the IPFS public chat (available via IRC, Matrix and Discord) |
Over at OpenBazaar (see here) we're using IPFS as a library (not as a deamon). The main author of the current code is @cpacia. As an example, this is his
AddFile
function (taken from here)I was curious about what the functions
PreRun
,Run
, andPostRun
do, and this is what Chris had to sayCould the
go-ipfs
team help theopenbazaar-go
team usego-ipfs
as a library? Specifically,PreRun
,Run
, etc. properly in the above code?go-ipfs
as a library?go-ipfs
as a library?Thanks! 👍
The text was updated successfully, but these errors were encountered: