status-go/vendor/github.com/ipfs/go-cid
Andrea Maria Piana 4d15ae8a85 Upgrade to go 1.18 2022-05-11 12:39:54 +01:00
..
.gitignore migrate to go 1.12 and go modules 2019-06-12 13:12:00 +02:00
.travis.yml go-waku integration (#2247) 2021-06-16 16:19:45 -04:00
LICENSE migrate to go 1.12 and go modules 2019-06-12 13:12:00 +02:00
Makefile go-waku integration (#2247) 2021-06-16 16:19:45 -04:00
README.md go-waku integration (#2247) 2021-06-16 16:19:45 -04:00
builder.go go-waku integration (#2247) 2021-06-16 16:19:45 -04:00
cid.go go-waku integration (#2247) 2021-06-16 16:19:45 -04:00
cid_fuzz.go migrate to go 1.12 and go modules 2019-06-12 13:12:00 +02:00
codecov.yml migrate to go 1.12 and go modules 2019-06-12 13:12:00 +02:00
deprecated.go migrate to go 1.12 and go modules 2019-06-12 13:12:00 +02:00
set.go migrate to go 1.12 and go modules 2019-06-12 13:12:00 +02:00
varint.go go-waku integration (#2247) 2021-06-16 16:19:45 -04:00

README.md

go-cid

GoDoc Coverage Status Travis CI

A package to handle content IDs in Go.

This is an implementation in Go of the CID spec. It is used in go-ipfs and related packages to refer to a typed hunk of data.

Lead Maintainer

Eric Myhre

Table of Contents

Install

go-cid is a standard Go module which can be installed with:

go get github.com/ipfs/go-cid

Usage

Running tests

Run tests with go test from the directory root

go test

Examples

Parsing string input from users

// Create a cid from a marshaled string
c, err := cid.Decode("bafzbeigai3eoy2ccc7ybwjfz5r3rdxqrinwi4rwytly24tdbh6yk7zslrm")
if err != nil {...}

fmt.Println("Got CID: ", c)

Creating a CID from scratch

// Create a cid manually by specifying the 'prefix' parameters
pref := cid.Prefix{
	Version: 1,
	Codec: cid.Raw,
	MhType: mh.SHA2_256,
	MhLength: -1, // default length
}

// And then feed it some data
c, err := pref.Sum([]byte("Hello World!"))
if err != nil {...}

fmt.Println("Created CID: ", c)

Check if two CIDs match

// To test if two cid's are equivalent, be sure to use the 'Equals' method:
if c1.Equals(c2) {
	fmt.Println("These two refer to the same exact data!")
}

Check if some data matches a given CID

// To check if some data matches a given cid, 
// Get your CIDs prefix, and use that to sum the data in question:
other, err := c.Prefix().Sum(mydata)
if err != nil {...}

if !c.Equals(other) {
	fmt.Println("This data is different.")
}

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Jeromy Johnson