Skip to content

Instantly share code, notes, and snippets.

@vasa-develop
Created January 22, 2020 22:09

Revisions

  1. vasa-develop created this gist Jan 22, 2020.
    22 changes: 22 additions & 0 deletions go-ipld-p2-3.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    // Map the struct instance to the mapping
    DocStoreMap[inputID] = employeeObject

    // Converting the map into JSON object
    entryJSON, err := json.Marshal(DocStoreMap)
    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 document entry is:")
    fmt.Println(jsonStr)

    start := time.Now()
    // Dag PUT operation which will return the CID for futher access or pinning etc.
    cid, err := sh.DagPut(entryJSON, "json", "cbor")
    elapsed := time.Since(start)
    if err != nil {
    fmt.Fprintf(os.Stderr, "error: %s", err)
    os.Exit(1)
    }