Code Monkey home page Code Monkey logo

ipldcrud's Introduction

ipld-crud

A simple Golang based hack to experiment the uses of IPLD through the DAG operations using the go-ipfs-api package.

I have built a tiny client that receives key-value entries from user and stores it on IPFS DAG, returning an explorable URL to play with.

Usage

Here is a sample main.go file for your quick reference:

package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"os"

	ipldcrud "github.com/0zAND1z/ipldcrud"
)

func main() {
	sh := ipldcrud.InitShell("https://ipfs.infura.io:5001")

	keyValueMap := make(map[string]interface{})

	scanner := bufio.NewScanner(os.Stdin)

	fmt.Println("Enter value for the key field: ")
	scanner.Scan()
	inputKey := scanner.Text()

	fmt.Println("Enter value for value field: ")
	scanner.Scan()
	inputValue := scanner.Text()

	keyValueMap[inputKey] = inputValue

	// Converting into JSON object
	entryJSON, err := json.Marshal(keyValueMap)
	if err != nil {
		fmt.Println(err)
	}

	// Display the marshaled JSON object before sending it to IPFS
	jsonStr := string(entryJSON)
	fmt.Println("The JSON object of your key-value entry is:")
	fmt.Println(jsonStr)
	cid := ipldcrud.Set(sh, entryJSON)
	fmt.Println("CID: ", cid)

	// Fetch the details by reading the DAG for key "inputKey"
	fmt.Printf("READ: Value for key \"%s\" is: ", inputKey)
	res, err := ipldcrud.Get(sh, cid, inputKey)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(res)
}
  1. Once you run the main.go, a simple console pops up, asking you to enter a key and a value.

  2. After entering two string values, it will create a dag entry based on the input data. It will subsequently query the same data and return back the result along with the query results.

Tutorial

For a more detailed understanding of IPLD and how the code works, check out this article on SimpleAsWater.com!

ipldcrud's People

Contributors

0zand1z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

pankaj-nayak

ipldcrud's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.