levelrail

package
v1.5.13 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package levelrail is a small client for the Levelrail control plane API. The operation table is generated from docs/public/openapi.json; the methods here cover a core set, and Invoke reaches any other operation by id.

Index

Examples

Constants

View Source
const (
	DefaultTimeout       = 30 * time.Second
	DefaultMaxFrameBytes = 4 << 20
)

DefaultTimeout bounds one non-streaming call; DefaultMaxFrameBytes bounds one SSE frame.

Variables

View Source
var ErrFrameTooLarge = errors.New("levelrail: SSE frame too large")

ErrFrameTooLarge means one SSE frame exceeded the byte cap.

View Source
var Operations = map[string]Operation{}/* 2424 elements not displayed */

Operations maps every OpenAPI operationId to its method and path template.

Functions

func Paginate

func Paginate[T any](ctx context.Context, fetch func(ctx context.Context, cursor string) ([]T, string, error)) iter.Seq2[T, error]

Paginate walks a cursor-paged list route. fetch returns one page and the next cursor; iteration stops at an empty cursor, an error or an early break.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/GLINCKER/levelrail/sdk/go/levelrail"
)

// exampleURL is a placeholder. Point LEVELRAIL_API_URL at a real control plane.
const exampleURL = "https://levelrail.example.com"

func newExampleClient() *levelrail.Client {
	return levelrail.New(exampleURL, os.Getenv("LEVELRAIL_TOKEN"))
}

func main() {
	client := newExampleClient()
	fetch := func(ctx context.Context, cursor string) ([]levelrail.Object, string, error) {
		return client.ListApps(ctx, levelrail.ListOptions{Limit: 50, Cursor: cursor})
	}
	for app, err := range levelrail.Paginate(context.Background(), fetch) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(app["name"])
	}
}

func ReadSSE

func ReadSSE(r io.Reader) iter.Seq2[SSEEvent, error]

ReadSSE parses a text/event-stream body with the default frame cap.

func ReadSSEMax

func ReadSSEMax(r io.Reader, maxFrame int) iter.Seq2[SSEEvent, error]

ReadSSEMax parses a text/event-stream body. Comment lines are skipped and a frame over maxFrame bytes (lines without a blank separator) is an error.

func WithIdempotencyKey

func WithIdempotencyKey(ctx context.Context, key string) context.Context

WithIdempotencyKey makes a create or deploy call safe to retry.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/GLINCKER/levelrail/sdk/go/levelrail"
)

// exampleURL is a placeholder. Point LEVELRAIL_API_URL at a real control plane.
const exampleURL = "https://levelrail.example.com"

func newExampleClient() *levelrail.Client {
	return levelrail.New(exampleURL, os.Getenv("LEVELRAIL_TOKEN"))
}

func main() {
	ctx := levelrail.WithIdempotencyKey(context.Background(), "deploy-web-2026-11-24")
	client := newExampleClient()
	deploy, err := client.DeployApp(ctx, "web", nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(deploy)
}

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError is a non-2xx response. The message never echoes request bodies.

func (*APIError) Error

func (e *APIError) Error() string

type ChangeEvent

type ChangeEvent struct {
	Topics      []string
	Heartbeat   bool
	HeartbeatMS int64
}

ChangeEvent is a nudge naming the topics that changed, or a heartbeat.

type Client

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

Client talks to one control plane with a bearer API token.

func New

func New(baseURL, token string, opts ...Option) *Client

New returns a client for baseURL (for example https://control.example.com).

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/GLINCKER/levelrail/sdk/go/levelrail"
)

// exampleURL is a placeholder. Point LEVELRAIL_API_URL at a real control plane.
const exampleURL = "https://levelrail.example.com"

func main() {
	client := levelrail.New(exampleURL, os.Getenv("LEVELRAIL_TOKEN"),
		levelrail.WithTimeout(10*time.Second))
	health, err := client.Health(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(health)
}

func (*Client) AllApps

func (c *Client) AllApps(ctx context.Context, o ListOptions) iter.Seq2[Object, error]

AllApps iterates every app, fetching pages of o.Limit on demand.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/GLINCKER/levelrail/sdk/go/levelrail"
)

// exampleURL is a placeholder. Point LEVELRAIL_API_URL at a real control plane.
const exampleURL = "https://levelrail.example.com"

func newExampleClient() *levelrail.Client {
	return levelrail.New(exampleURL, os.Getenv("LEVELRAIL_TOKEN"))
}

func main() {
	client := newExampleClient()
	for app, err := range client.AllApps(context.Background(), levelrail.ListOptions{Limit: 100}) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(app["name"])
	}
}

func (*Client) Changes

func (c *Client) Changes(ctx context.Context) iter.Seq2[ChangeEvent, error]

Changes streams GET /api/v1/events/changes until ctx ends or the server closes the stream. Callers reconnect and refetch on error or end of stream.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/GLINCKER/levelrail/sdk/go/levelrail"
)

// exampleURL is a placeholder. Point LEVELRAIL_API_URL at a real control plane.
const exampleURL = "https://levelrail.example.com"

func newExampleClient() *levelrail.Client {
	return levelrail.New(exampleURL, os.Getenv("LEVELRAIL_TOKEN"))
}

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	client := newExampleClient()
	for ev, err := range client.Changes(ctx) {
		if err != nil {
			// Reconnect and refetch state on error or end of stream.
			log.Print(err)
			return
		}
		if ev.Heartbeat {
			continue
		}
		fmt.Println("changed:", ev.Topics)
	}
}

func (*Client) CreateApp

func (c *Client) CreateApp(ctx context.Context, body Object) (Object, error)

CreateApp creates an app from a JSON body (see the API reference for fields).

func (*Client) DeployApp

func (c *Client) DeployApp(ctx context.Context, name string, body Object) (Object, error)

DeployApp triggers a deploy. A nil body deploys the app as configured.

func (*Client) GetApp

func (c *Client) GetApp(ctx context.Context, name string) (Object, error)

GetApp returns one app.

func (*Client) GetEnv

func (c *Client) GetEnv(ctx context.Context, name string) ([]Object, error)

GetEnv returns the variables bound to an app. The server masks secret values.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (Object, error)

Health reports whether the control plane answers.

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, opID string, params []string, q url.Values, body, out any) (http.Header, error)

Invoke calls any operation by id and decodes the JSON response into out (nil to discard). It returns the response headers.

func (*Client) ListApps

func (c *Client) ListApps(ctx context.Context, o ListOptions) ([]Object, string, error)

ListApps returns one page of apps and the cursor of the next page ("" at the end).

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/GLINCKER/levelrail/sdk/go/levelrail"
)

// exampleURL is a placeholder. Point LEVELRAIL_API_URL at a real control plane.
const exampleURL = "https://levelrail.example.com"

func newExampleClient() *levelrail.Client {
	return levelrail.New(exampleURL, os.Getenv("LEVELRAIL_TOKEN"))
}

func main() {
	client := newExampleClient()
	apps, next, err := client.ListApps(context.Background(), levelrail.ListOptions{Limit: 50})
	if err != nil {
		log.Fatal(err)
	}
	for _, app := range apps {
		fmt.Println(app["name"])
	}
	if next != "" {
		fmt.Println("next cursor:", next)
	}
}

func (*Client) ListDeploys

func (c *Client) ListDeploys(ctx context.Context, name string) ([]Object, error)

ListDeploys returns the deploy history of an app.

func (*Client) RollbackApp

func (c *Client) RollbackApp(ctx context.Context, name, deployID string) (Object, error)

RollbackApp redeploys the release of an earlier deploy.

func (*Client) SetEnv

func (c *Client) SetEnv(ctx context.Context, name string, vars map[string]string) (Object, error)

SetEnv replaces the plain environment of an app with vars and returns the updated app. Values are sent once and never logged or put into errors.

type ListOptions

type ListOptions struct {
	Limit  int
	Cursor string
	Query  string
}

ListOptions narrows a list call. Zero values are omitted.

type Object

type Object = map[string]any

Object is a decoded JSON object. Most responses are not typed in the spec.

type Operation

type Operation struct {
	Method  string
	Path    string
	HasBody bool
	Stream  bool
}

Operation describes one OpenAPI operation.

type Option

type Option func(*Client)

Option customizes a Client.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient replaces the default http.Client, for timeouts or transports.

func WithMaxFrameBytes

func WithMaxFrameBytes(n int) Option

WithMaxFrameBytes caps the bytes of one SSE frame before ReadSSE errors.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the per-call timeout of the default client (streams exempt).

type SSEEvent

type SSEEvent struct {
	Event string
	ID    string
	Data  string
}

SSEEvent is one server-sent event frame.

Jump to

Keyboard shortcuts

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