40c5ff1bfe82a17fd9d620e111c3df93567db79b
go-cid
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.
Table of Contents
Install
make deps
Examples
To use CIDs, import it in your code like:
import "github.com/ipfs/go-cid"
Then, depending on how you want to use it, something like one of the following examples should work:
Parsing string input from users
// Create a cid from a marshaled string
c, err := cid.Decode("zdvgqEMYmNeH5fKciougvQcfzMcNjF3Z1tPouJ8C7pc3pe63k")
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
Description
Languages
Go
99.9%
Makefile
0.1%