sdk

package
v0.1.155 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package sdk provides helpers for codefly-managed services.

Use WithDependencies for CLI-based dependency management, or Env for direct agent management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connection

func Connection(service, name string) string

Connection returns a connection string from environment variables.

func HasValidExtension

func HasValidExtension(path string, extensions []string) bool

HasValidExtension checks if the file has one of the specified extensions

func Inject

func Inject(env *resources.EnvironmentVariable)

func Module

func Module() (*resources.Module, error)

func RecreateDirectory

func RecreateDirectory(request *utils.Directory, destPath string) error

func SerializeDirectory

func SerializeDirectory(rootPath string, extensions []string) (*utils.Directory, error)

SerializeDirectory walks through the given directory and creates a DirectoryRequest containing FileInfo for files with the specified extensions.

func Service

func Service() (*resources.Service, error)

Types

type Dependencies

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

Dependencies manages a running set of codefly-managed service dependencies. The underlying CLI subprocess runs in its own process group via managedProcess so Destroy can tear down the entire tree — the CLI, its spawned agents, and their containers — with a single group kill. Without this, `go test` leaks containers and hangs on WaitDelay waiting for inherited stdout/stderr FDs.

func WithDependencies

func WithDependencies(ctx context.Context, opts ...OptionFunc) (*Dependencies, error)

WithDependencies starts all dependencies declared in the current service's service.codefly.yaml using the codefly CLI. This handles arbitrarily deep dependency graphs — the CLI resolves and starts everything in order.

Connection strings are injected as environment variables (the standard codefly pattern). Use Connection() or os.Getenv() to retrieve them.

Usage:

deps, err := sdk.WithDependencies(ctx)
deps, err := sdk.WithDependencies(ctx, sdk.WithDebug())
deps, err := sdk.WithDependencies(ctx, sdk.WithTimeout(30*time.Second))

func (*Dependencies) Destroy

func (l *Dependencies) Destroy(ctx context.Context) error

Destroy tears down all running dependencies. Same guarantee as Stop but instructs the CLI to DestroyFlow (which removes state, not just stopping processes) before killing the subprocess group.

func (*Dependencies) SetEnvironment

func (l *Dependencies) SetEnvironment(ctx context.Context) error

func (*Dependencies) Stop

func (l *Dependencies) Stop(ctx context.Context) error

Stop gracefully stops all running dependencies. Sends StopFlow to the CLI (which triggers the agents' own cleanup), then kills the CLI subprocess group — belt and suspenders so we always take the whole tree down.

func (*Dependencies) WaitForReady

func (l *Dependencies) WaitForReady(ctx context.Context, opt *Option) error

type Env

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

Env manages a set of codefly services.

func New deprecated

func New() *Env

New creates a new environment.

Deprecated: Use WithDependencies instead.

func (*Env) Add deprecated

func (e *Env) Add(agentName string) *Env

Add registers a codefly service agent to be started.

Deprecated: Use WithDependencies which reads service.codefly.yaml.

func (*Env) Connection

func (e *Env) Connection(agentName, name string) string

Connection returns a connection string for a running service.

func (*Env) Connections

func (e *Env) Connections(agentName string) map[string]string

Connections returns all connection strings for a running service.

func (*Env) Load

func (e *Env) Load(dir string) (*Env, error)

Load reads service.codefly.yaml from dir and adds all declared service-dependencies.

func (*Env) Start

func (e *Env) Start(ctx context.Context) error

Start starts all registered services.

func (*Env) Stop

func (e *Env) Stop(ctx context.Context) error

Stop destroys all running services and cleans up.

type Option

type Option struct {
	Debug       bool
	Timeout     time.Duration
	NamingScope string
	Silents     []string
}

type OptionFunc

type OptionFunc func(*Option)

func WithDebug

func WithDebug() OptionFunc

func WithNamingScope

func WithNamingScope(scope string) OptionFunc

func WithSilence

func WithSilence(uniques ...string) OptionFunc

func WithTimeout

func WithTimeout(timeout time.Duration) OptionFunc

Jump to

Keyboard shortcuts

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