compute

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

compute-go

Go client library for Suborbital Compute

Usage

In a Go project, run

go get github.com/suborbital/compute-go@latest

Every operation with Compute is done with a compute.Client. Here's a simple example that fetches exisiting Runnables for a user and namespace.

package main

import (
    "log"

    "github.com/suborbital/compute-go"
)

func main() {
	token, err := os.LookupEnv("SCC_ENV_TOKEN")
    if err != nil {
        log.Fatal(err)
    }

	client, err := compute.NewClient(compute.LocalConfig(), token)
    if err != nil {
        log.Fatal(err)
    }

    // get a list of Runnables
    runnables, err := client.UserFunctions("userID", "namespace")
    if err != nil {
        log.Fatal(err)
    }

    for _, r := range runnables {
        log.Println(r.FQFN)
    }
}

See examples folder for more.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRunnable

func NewRunnable(environment, userId, namespace, fnName, language string) *directive.Runnable

NewRunnable instantiates a local v1.0.0 Runnable that can be used for various calls with compute.Client. Note: this constructor alone does not perform any actions on a remote Compute instance.

func NewRunnableVersion

func NewRunnableVersion(environment, userId, namespace, fnName, version, language string) *directive.Runnable

NewRunnableVersion instantiates a local versioned Runnable that can be used for various calls with compute.Client. Note: this constructor alone does not perform any actions on a remote Compute instance.

Types

type BuildResult

type BuildResult struct {
	Succeeded bool   `json:"succeeded"`
	OutputLog string `json:"outputLog"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is used for interacting with the Suborbital Compute API

func NewClient

func NewClient(config *Config, envToken string) (*Client, error)

NewClient creates a Client with a Config

func NewLocalClient

func NewLocalClient(envToken string) (*Client, error)

NewLocalClient quickly sets up a Client with a LocalConfig. Useful for testing.

func (*Client) BuildFunction

func (c *Client) BuildFunction(runnable *directive.Runnable, functionBody io.Reader) (*BuildResult, error)

BuildFunction triggers a remote build for the given Runnable and function body. See also: Client.BuildFunctionString()

Example

This function is useful for reading from a filesystem or from an http.Response.Body

runnable := compute.NewRunnable("com.suborbital", "acmeco", "default", "hello", "rust")
file, _ := os.Open("hello.rs")
result, err := client.BuildFunction(runnable, file)

func (*Client) BuildFunctionString

func (c *Client) BuildFunctionString(runnable *directive.Runnable, functionString string) (*BuildResult, error)

BuildFunctionString triggers a remote build for the given Runnable and function string. See also: Client.BuildFunction()

func (*Client) BuilderFeatures

func (c *Client) BuilderFeatures() (*FeaturesResponse, error)

BuilderFeatures lists the features present on the builder, such as testing capabilities.

func (*Client) BuilderHealth

func (c *Client) BuilderHealth() (bool, error)

BuilderHealth is used to check that the builder is healthy and responding to requests.

func (*Client) BuilderTemplate

func (c *Client) BuilderTemplate(runnable *directive.Runnable) (*EditorStateResponse, error)

BuilderTemplate gets the function template for the provided Runnable. The Runnable must have the .Lang, .Name, and .Namespace fields set.

func (*Client) EditorToken

func (c *Client) EditorToken(runnable *directive.Runnable) (string, error)

EditorToken gets an editor token for the provided Runnable. Note: this library manages editor tokens for you, so you most likely do not need to use this function.

func (*Client) Exec

func (c *Client) Exec(runnable *directive.Runnable, body io.Reader) ([]byte, string, error)

Exec remotely executes the provided runnable using the body as input. See also: ExecString()

func (*Client) ExecString

func (c *Client) ExecString(runnable *directive.Runnable, body string) ([]byte, string, error)

ExecString sets up a buffer with the provided string and calls Exec

func (*Client) FunctionResult added in v0.1.0

func (c *Client) FunctionResult(uuid string) ([]byte, error)

FunctionResult returns the result of the provided runnable execution.

func (*Client) FunctionResultMetadata added in v0.1.0

func (c *Client) FunctionResultMetadata(uuid string) (*ExecMetadata, error)

FunctionResultMetadata returns metadata for the provided runnable execution.

func (*Client) FunctionResultsMetadata added in v0.1.0

func (c *Client) FunctionResultsMetadata(runnable *directive.Runnable) ([]ExecMetadata, error)

FunctionResultsMetadata returns metadata for the 5 most recent execution results for the provided runnable.

func (*Client) GetDraft

func (c *Client) GetDraft(runnable *directive.Runnable) (*EditorStateResponse, error)

GetDraft gets the most recently build source code for the provided Runnable. Must have the .FQFNURI field set.

func (*Client) PromoteDraft

func (c *Client) PromoteDraft(runnable *directive.Runnable) (*PromoteDraftResponse, error)

PromoteDraft takes the most recent build of the provided runnable and deploys it so it can be run. The .Version field of the provided runnable is modified in place if the promotion is successful.

func (*Client) UserFunctions

func (c *Client) UserFunctions(identifier string, namespace string) ([]*directive.Runnable, error)

UserFunctions gets a list of the deployed runnables for the given identifier and namespace.

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config combines the common configuration options for the three Suborbital Compute APIs (Administrative, Builder, and Execution)

func CustomConfig added in v0.1.2

func CustomConfig(execHost string, adminHost string, builderHost string) (*Config, error)

Custom Configuration

func DefaultConfig

func DefaultConfig(builderHost string) (*Config, error)

DefaultConfig takes the given host and creates a Compute config with the K8S default ports. Everything except the scheme and hostname are considered. You need to provide your builder host domain.

func LocalConfig

func LocalConfig() *Config

LocalConfig generates a Configuration for Compute running in docker-compose

type EditorStateResponse

type EditorStateResponse struct {
	Lang     string        `json:"lang"`
	Contents string        `json:"contents"`
	Tests    []TestPayload `json:"tests"`
}

EditorStateResponse is a response to requests to get editorState

type ExecError

type ExecError struct {
	Code    int    `json:"code"`
	Message string `json:"string"`
}

type ExecMetadata added in v0.1.0

type ExecMetadata struct {
	UUID      string    `json:"uuid"`
	Timestamp time.Time `json:"timestamp"`
	Success   bool      `json:"success"`
	Error     ExecError `json:"error"`
}

type ExecResponse added in v0.1.0

type ExecResponse struct {
	Response []byte
	UUID     string
}

type FeatureLanguage added in v0.1.1

type FeatureLanguage struct {
	ID     string `json:"identifier"`
	Short  string `json:"short"`
	Pretty string `json:"pretty"`
}

type FeaturesResponse

type FeaturesResponse struct {
	Features  []string          `json:"features"`
	Langauges []FeatureLanguage `json:"languages"`
}

type PromoteDraftResponse

type PromoteDraftResponse struct {
	Version string `json:"version"`
}

type TestPayload

type TestPayload struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Payload     string `json:"payload"`
}

TestPayload is a single test for a Runnable

type TokenResponse

type TokenResponse struct {
	Token string `json:"token"`
}

type UserFunctionsResponse

type UserFunctionsResponse struct {
	Functions []*directive.Runnable `json:"functions"`
}

Directories

Path Synopsis
examples
app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL