/
View dependency graph
Depends on
- dh-golang (dh-sequence-golang)
- golang-defaults (golang-any)
- golang-github-multiformats-go-base32 (golang-github-multiformats-go-base32-dev)
- golang-github-multiformats-go-base36 (golang-github-multiformats-go-base36-dev)
- golang-github-multiformats-go-multibase (golang-github-multiformats-go-multibase-dev)
- golang-github-multiformats-go-multihash (golang-github-multiformats-go-multihash-dev)
- golang-github-multiformats-go-varint (golang-github-multiformats-go-varint-dev)
- debhelper-compat
README (full)
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.
Lead Maintainer
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
import (
cid "github.com/ipfs/go-cid"
mc "github.com/multiformats/go-multicodec"
mh "github.com/multiformats/go-multihash"
)
// Create a cid manually by specifying the 'prefix' parameters
pref := cid.Prefix{
Version: 1,
Codec: uint64(mc.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
| dir | .github/ |
| dir | _rsrch/ |
| dir | debian/ |
| dir | fuzz-data/ |
| file | .gitignore |
| file | LICENSE |
| file | Makefile |
| file | README.md |
| file | benchmark_test.go |
| file | builder.go |
| file | builder_test.go |
| file | cid.go |
| file | cid_fuzz.go |
| file | cid_test.go |
| file | codecov.yml |
| file | deprecated.go |
| file | go.mod |
| file | go.sum |
| file | set.go |
| file | set_test.go |
| file | varint.go |
| file | varint_test.go |
| file | version.json |