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 ¶
- Constants
- Variables
- func Paginate[T any](ctx context.Context, ...) iter.Seq2[T, error]
- func ReadSSE(r io.Reader) iter.Seq2[SSEEvent, error]
- func ReadSSEMax(r io.Reader, maxFrame int) iter.Seq2[SSEEvent, error]
- func WithIdempotencyKey(ctx context.Context, key string) context.Context
- type APIError
- type ChangeEvent
- type Client
- func (c *Client) AllApps(ctx context.Context, o ListOptions) iter.Seq2[Object, error]
- func (c *Client) Changes(ctx context.Context) iter.Seq2[ChangeEvent, error]
- func (c *Client) CreateApp(ctx context.Context, body Object) (Object, error)
- func (c *Client) DeployApp(ctx context.Context, name string, body Object) (Object, error)
- func (c *Client) GetApp(ctx context.Context, name string) (Object, error)
- func (c *Client) GetEnv(ctx context.Context, name string) ([]Object, error)
- func (c *Client) Health(ctx context.Context) (Object, error)
- func (c *Client) Invoke(ctx context.Context, opID string, params []string, q url.Values, body, out any) (http.Header, error)
- func (c *Client) ListApps(ctx context.Context, o ListOptions) ([]Object, string, error)
- func (c *Client) ListDeploys(ctx context.Context, name string) ([]Object, error)
- func (c *Client) RollbackApp(ctx context.Context, name, deployID string) (Object, error)
- func (c *Client) SetEnv(ctx context.Context, name string, vars map[string]string) (Object, error)
- type ListOptions
- type Object
- type Operation
- type Option
- type SSEEvent
Examples ¶
Constants ¶
const ( DefaultTimeout = 30 * time.Second DefaultMaxFrameBytes = 4 << 20 )
DefaultTimeout bounds one non-streaming call; DefaultMaxFrameBytes bounds one SSE frame.
Variables ¶
var ErrFrameTooLarge = errors.New("levelrail: SSE frame too large")
ErrFrameTooLarge means one SSE frame exceeded the byte cap.
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"])
}
}
Output:
func ReadSSEMax ¶
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 ¶
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)
}
Output:
Types ¶
type ChangeEvent ¶
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 ¶
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)
}
Output:
func (*Client) AllApps ¶
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"])
}
}
Output:
func (*Client) Changes ¶
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)
}
}
Output:
func (*Client) CreateApp ¶
CreateApp creates an app from a JSON body (see the API reference for fields).
func (*Client) GetEnv ¶
GetEnv returns the variables bound to an app. The server masks secret values.
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 ¶
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)
}
}
Output:
func (*Client) ListDeploys ¶
ListDeploys returns the deploy history of an app.
func (*Client) RollbackApp ¶
RollbackApp redeploys the release of an earlier deploy.
type ListOptions ¶
ListOptions narrows a list call. Zero values are omitted.
type Option ¶
type Option func(*Client)
Option customizes a Client.
func WithHTTPClient ¶
WithHTTPClient replaces the default http.Client, for timeouts or transports.
func WithMaxFrameBytes ¶
WithMaxFrameBytes caps the bytes of one SSE frame before ReadSSE errors.
func WithTimeout ¶
WithTimeout sets the per-call timeout of the default client (streams exempt).