Computes Go SDK

Jade Meskill
computes
Published in
2 min readMay 2, 2018

Today we are launching the Go SDK for Computes. The SDK allows Gophers to easily integrate with the Computes Mesh Computer. I’ll post soon on explaining the fundamental components of Computes, for now you can explore the help wiki.

The create-task example in the SDK shows how to use some of the convenience methods provided, let’s take a walk through some of the code.

input, err := POLYMORPH.FromInterface(ipfsURL, 2)

Polymorphs allow us to refer to an IPLD link or raw data. In this case, we want to pass the integer 2 as the data in the polymorph. Representing such an interface in Go can be problematic, so we’ve created a library that uses json.RawMessage to make it easier.

statusHash, err := datasets.Create(computesURL)
status := POLYMORPH.FromRef(ipfsURL, statusHash)
resultsHash, err := datasets.Create(computesURL)
results := POLYMORPH.FromRef(ipfsURL, resultsHash)

In this case, the polymorph references the IPFS CID of the dataset. The dataset is a merkle tree. Since IPFS is immutable, we constantly add new nodes to the merkle tree and track the new head CID. The origin of the merkle tree is all that is needed to look up the latest.

For a task, two datasets are required, the task status and the results hash. The task status should be unique for every task, but the results may be shared with many tasks.

task := &types.Task{
Input: &types.DatasetLink{
Dataset: input,
},
TaskDefinition: definition,
Status: status,
}

The types package helps to easily create the data structures required for a Computes Task.

hash, err := DAG.PutInterface(ipfsURL, task)
err = tasks.Enqueue(computesURL, hash)

This will take the task as defined above and add an IPFS DAG entry. That CID is then passed to Computes, added to the queue, and then the task should be run by a member of the Computes Mesh.

If we take a look at the task in JSON notation, this is what it will look like.

{
"input": {
"dataset": 2
},
"status": {
"/": "zdpuAkeWGt1gXzzbogppUGUXxTZeULtXzN2VBxg3y8kgy4x7z"
},
"taskDefinition": {
"result": {
"dataset": {
"/": "zdpuB1yueDsESCo2GPmHXxf7N2JB1v9LqKHGBSqTwENQEmKWN"
},
"path": "split/results"
},
"runner": {
"metadata": {
"image": "computes/fibonacci-sum-split:latest"
},
"type": "docker-json-runner"
}
}
}

Please explore the SDK and especially the example app to get a better understanding of integrating Computes with your go application. We will be providing SDKs for other languages in the near future.

There is also an example application that shows how to add tasks to Computes and check results. The example will calculate N digits of the Fibonacci sequence and display the results and monitor all the tasks involved.

--

--

Jade Meskill
computes

Boring Human. Making Music. Creating Code. Making a mess of things… Magic Leaper, Co-founder of Gangplank