GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ipfs/go-cid: Content ID v1 implemented in go

BranchesTags
Open more actions menu

Latest commit

 

History

341 Commits
341 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
_rsrch/internal/cidiface
_rsrch/internal/cidiface
 
 
fuzz-data/corpus
fuzz-data/corpus
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
benchmark_test.go
benchmark_test.go
 
 
builder.go
builder.go
 
 
builder_test.go
builder_test.go
 
 
cid.go
cid.go
 
 
cid_fuzz.go
cid_fuzz.go
 
 
cid_test.go
cid_test.go
 
 
codecov.yml
codecov.yml
 
 
deprecated.go
deprecated.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
set.go
set.go
 
 
set_test.go
set_test.go
 
 
varint.go
varint.go
 
 
varint_test.go
varint_test.go
 
 
version.json
version.json
 
 

Repository files navigation

go-cid

GoDoc Coverage Status Build Status

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
  • Contribute
  • License

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

About

Content ID v1 implemented in go

Topics

cidipldmultiformats

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

172 stars

Watchers

25 watching

Forks

51 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.