Skip to main content

Using Compute from Go

The compute-go library helps you easily interact with the Compute API from your Go application. Suborbital Compute is designed to run alongside your application in a Kubernetes or Docker Compose environment.


Like most Go packages, you can find complete and up to date technical documentation for compute-go on Those docs are generated from inline comments in the compute-go source code.


In a directory with a go.mod file, run:

go get

Basic Usage


This example sets up a basic client with the token generated in "Setup" or with the web app. The compute.Client object created here assumes that Compute is running on the same host on its default ports. Feel free to check out the code for this example!

package main

import (


func client() *compute.Client {
token, _ := os.LookupEnv("SCC_ENV_TOKEN")
client, _ := compute.NewClient(compute.LocalConfig(), token)

return client

Build and run a function

We can now integrate Compute into an application. compute-go has access to all of Compute's APIs. It can run builds, list existing functions, run tests, and execute functions.

Behind the scenes, compute-go manages authentication, so you don't have to worry about setting the right HTTP headers when interacting with the Compute API.

package main

import (


func main() {
client := client()

// This is a local reference to some Runnable. Nothing has run in Compute at this point.
runnable := compute.NewRunnable("com.suborbital", "acmeco", "default", "rs-hello-world", "rust")

// Request template source code for the above Runnable.
template, _ := client.BuilderTemplate(runnable)

// Log the default 'hello world' Rust template to stdout

// Run a remote build for the provided Runnable and the unmodified 'hello world'
// template source code.
build, _ := client.BuildFunctionString(runnable, template.Contents)

if !build.Succeeded {
// Log the compiler output to see why the build failed

// Deploy the function (the runnable's .Version field is adjusted here)

// Execute the function
result, _ := client.ExecString(runnable, "world!")

// Log the execution output

Now that the Runnable has been built, it can be executed as much as you like without rebuilding using client.Exec or client.ExecString.