The Central Go Modules Repository

To use GoCenter:
export GOPROXY=
May 12th 2020
Last Modified


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.

Table of Contents

  • Install
  • Usage
  • API
  • Contribute
  • License


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

go get

Note that go-cid is packaged with Gx, so it is recommended to use Gx to install and use it (see Usage section).


Using Gx and Gx-go

This module is packaged with Gx. In order to use it in your own project it is recommended that you:

go get -u
go get -u
cd <your-project-repository>
gx init
gx import
gx install --global
gx-go --rewrite

Please check Gx and Gx-go documentation for more information.

Running tests

Before running tests, please run:

make deps

This will make sure that dependencies are rewritten to known working versions.


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.")


PRs are welcome!

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


MIT © Jeromy Johnson