Go SDK#
Stdlib net/http only. Functional options. Synchronous API. Go 1.21+.
Install#
go get github.com/orkait/rustbox-sdk/go
Quickstart#
package main
import (
"fmt"
"os"
rustbox "github.com/orkait/rustbox-sdk/go"
)
func main() {
client := rustbox.New(os.Getenv("RUSTBOX_API_KEY"))
result, err := client.Run(rustbox.SubmitRequest{
Language: "python",
Code: "print('hello')",
})
if err != nil {
panic(err)
}
fmt.Println(result["verdict"], result["stdout"]) // AC hello
}
Run() submits, waits for sync completion, polls if needed, returns the verdict.
Errors#
import "errors"
result, err := client.Run(req)
switch {
case errors.Is(err, rustbox.ErrAuth): // 401/403 - check API key
case errors.Is(err, rustbox.ErrRateLimit): // 429 - back off
case errors.Is(err, rustbox.ErrServer): // 5xx - SDK already retried
case errors.Is(err, rustbox.ErrTimeout): // exceeded HTTP client timeout
}
Configuration#
rustbox.New(apiKey,
rustbox.WithBaseURL("https://rustbox.orkait.com"), // default
rustbox.WithMaxRetries(2), // default
rustbox.WithHTTPClient(&http.Client{Timeout: 65 * time.Second}),
)
Webhooks#
// Configure the webhook endpoint on the project in the dashboard first.
client.Submit(rustbox.SubmitRequest{
Language: "python",
Code: "...",
}, false) // wait=false, returns id immediately
See Webhooks for HMAC verification.