-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,66 @@ A simple Golang based hack to experiment the uses of IPLD through the DAG operat | |
|
||
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. | ||
|
||
## Instructions | ||
## Usage | ||
|
||
1. Clone the repo with the following command: | ||
```sh | ||
git clone [email protected]:0zAND1z/ipldcrud.git | ||
``` | ||
Here is a sample main.go file for your quick reference: | ||
|
||
```go | ||
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) | ||
} | ||
|
||
2. Run the program to initaite dialog: | ||
```sh | ||
go run main.go | ||
``` | ||
|
||
3. Once you run the main.go, a nice ASCII version of the IPFS logo pops up, asking you to enter a key and a value. | ||
1. Once you run the main.go, a simple console pops up, asking you to enter a key and a value. | ||
|
||
4. After entering two string values, it will create a dag entry based on the input data and return back the hash along with the query results. | ||
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 | ||
|
||
|