Go-ipfs: run go-ipfs-as-a-library example main.go Error

Created on 19 Nov 2019  ·  8Comments  ·  Source: ipfs/go-ipfs

Location

https://github.com/ipfs/go-ipfs/blob/master/docs/examples/go-ipfs-as-a-library/README.md

Description

I run main.go in the example directory and it seems good.

But when I move main.go to another location. It's not good and it seems I import the wrong packages.

Most appear is go-libp2p-core.

$ go run main.go 
# github.com/libp2p/go-libp2p-host
../go/pkg/mod/github.com/libp2p/[email protected]/helpers.go:8:3: cannot use h.ID() (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in field value
# github.com/libp2p/go-libp2p-swarm
../go/pkg/mod/github.com/libp2p/[email protected]/swarm.go:181:20: cannot use p (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in argument to s.peers.AddPubKey
../go/pkg/mod/github.com/libp2p/[email protected]/swarm.go:181:20: cannot use pk (type "github.com/libp2p/go-libp2p-crypto".PubKey) as type "github.com/libp2p/go-libp2p-core/crypto".PubKey in argument to s.peers.AddPubKey:
        "github.com/libp2p/go-libp2p-crypto".PubKey does not implement "github.com/libp2p/go-libp2p-core/crypto".PubKey (wrong type for Equals method)
                have Equals("github.com/libp2p/go-libp2p-crypto".Key) bool
                want Equals("github.com/libp2p/go-libp2p-core/crypto".Key) bool
../go/pkg/mod/github.com/libp2p/[email protected]/swarm_dial.go:285:25: cannot use s.local (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in argument to s.peers.PrivKey
../go/pkg/mod/github.com/libp2p/[email protected]/swarm_dial.go:300:28: cannot use p (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in argument to s.peers.Addrs
# github.com/libp2p/go-libp2p-kad-dht/pb
../go/pkg/mod/github.com/libp2p/[email protected]/pb/message.go:57:3: cannot use "github.com/libp2p/go-libp2p-peer".ID(pbp.GetId()) (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in field value
../go/pkg/mod/github.com/libp2p/[email protected]/pb/message.go:79:47: cannot use peers[i].ID (type "github.com/libp2p/go-libp2p-core/peer".ID) as type "github.com/libp2p/go-libp2p-peer".ID in argument to n.Connectedness
# github.com/libp2p/go-libp2p-kbucket
../go/pkg/mod/github.com/libp2p/[email protected]/table.go:81:27: cannot use p (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in argument to rt.metrics.LatencyEWMA
../go/pkg/mod/github.com/libp2p/[email protected]/table.go:246:66: cannot use p (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in argument to rt.metrics.LatencyEWMA
# github.com/libp2p/go-libp2p-routing-helpers
../go/pkg/mod/github.com/libp2p/[email protected]/parallel.go:431:20: cannot use pi.ID (type "github.com/libp2p/go-libp2p-core/peer".ID) as type "github.com/libp2p/go-libp2p-peer".ID in map index
../go/pkg/mod/github.com/libp2p/[email protected]/parallel.go:437:9: cannot use pi.ID (type "github.com/libp2p/go-libp2p-core/peer".ID) as type "github.com/libp2p/go-libp2p-peer".ID in map index
../go/pkg/mod/github.com/libp2p/[email protected]/parallel.go:485:19: cannot use pi.ID (type "github.com/libp2p/go-libp2p-core/peer".ID) as type "github.com/libp2p/go-libp2p-peer".ID in map index
../go/pkg/mod/github.com/libp2p/[email protected]/parallel.go:491:9: cannot use pi.ID (type "github.com/libp2p/go-libp2p-core/peer".ID) as type "github.com/libp2p/go-libp2p-peer".ID in map index
# github.com/ipfs/go-ipns
../go/pkg/mod/github.com/ipfs/[email protected]/record.go:77:26: cannot use pid (type "github.com/libp2p/go-libp2p-peer".ID) as type "github.com/libp2p/go-libp2p-core/peer".ID in argument to v.KeyBook.PubKey
../go/pkg/mod/github.com/ipfs/[email protected]/record.go:82:2: cannot use pubk (type "github.com/libp2p/go-libp2p-core/crypto".PubKey) as type "github.com/libp2p/go-libp2p-crypto".PubKey in return argument:
        "github.com/libp2p/go-libp2p-core/crypto".PubKey does not implement "github.com/libp2p/go-libp2p-crypto".PubKey (wrong type for Equals method)
                have Equals("github.com/libp2p/go-libp2p-core/crypto".Key) bool
                want Equals("github.com/libp2p/go-libp2p-crypto".Key) bool

Most helpful comment

I just remember what I did, just a go init my_package && go mod tidy.

@Jorropo I tried this, but the same problem.
@jonnycrunch yes, I replace github.com/ipfs/go-ipfs to github.com/ipfs/go-ipfs v0.4.22-0.20191119151441-b8ec598d5801 . things gonna be Ok.
image

All 8 comments

Try with a copy of go-ipfs/go.{mod,sum}, also don't forget to change the module in the new go.mod to your package name.

you're right! I just copy gomod and gosum but not change the module name.

Oops, I change the module name and not good.

I copy them, and copy main.go to a new directory, but also has this problem.

do you still have the same problem ?

Using go modules you need to require a specific commit as a dependency in the go.mod file i.e.

require(
    github.com/ipfs/go-ipfs v0.4.22-0.20191119151441-b8ec598d5801
)

and it's appropriate hash-link digest in go.sum:

github.com/ipfs/go-ipfs v0.4.22-0.20191119151441-b8ec598d5801 h1:XIYmA2bobIuP+cDk7bSZAXvdDidKlNfQEL/xCH+giSg=
github.com/ipfs/go-ipfs v0.4.22-0.20191119151441-b8ec598d5801/go.mod h1:fld7uJBHEH9mUMtbFZ5CQCVZpkQiwjIt2xuAyrNrPqE=

Latest release (v0.4.22) is out of date for this cutting edge feature. Likely fixed in 0.4.23 release 🤞.

I just remember what I did, just a go init my_package && go mod tidy.

I just remember what I did, just a go init my_package && go mod tidy.

@Jorropo I tried this, but the same problem.
@jonnycrunch yes, I replace github.com/ipfs/go-ipfs to github.com/ipfs/go-ipfs v0.4.22-0.20191119151441-b8ec598d5801 . things gonna be Ok.
image

I just remember what I did, just a go init my_package && go mod tidy.

@Jorropo I tried this, but the same problem.
@jonnycrunch yes, I replace github.com/ipfs/go-ipfs to github.com/ipfs/go-ipfs v0.4.22-0.20191119151441-b8ec598d5801 . things gonna be Ok.
image

感谢!

Was this page helpful?
0 / 5 - 0 ratings