Documentation
¶
Overview ¶
Package sdk provides helpers for codefly-managed services.
Use WithDependencies for CLI-based dependency management, or Env for direct agent management.
Index ¶
- func Connection(service, name string) string
- func HasValidExtension(path string, extensions []string) bool
- func Inject(env *resources.EnvironmentVariable)
- func Module() (*resources.Module, error)
- func RecreateDirectory(request *utils.Directory, destPath string) error
- func SerializeDirectory(rootPath string, extensions []string) (*utils.Directory, error)
- func Service() (*resources.Service, error)
- type Dependencies
- type Env
- func New() *Envdeprecated
- func (e *Env) Add(agentName string) *Envdeprecated
- func (e *Env) Connection(agentName, name string) string
- func (e *Env) Connections(agentName string) map[string]string
- func (e *Env) Load(dir string) (*Env, error)
- func (e *Env) Start(ctx context.Context) error
- func (e *Env) Stop(ctx context.Context) error
- type Option
- type OptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connection ¶
Connection returns a connection string from environment variables.
func HasValidExtension ¶
HasValidExtension checks if the file has one of the specified extensions
func Inject ¶
func Inject(env *resources.EnvironmentVariable)
func SerializeDirectory ¶
SerializeDirectory walks through the given directory and creates a DirectoryRequest containing FileInfo for files with the specified extensions.
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 (*Env) Connection ¶
Connection returns a connection string for a running service.
func (*Env) Connections ¶
Connections returns all connection strings for a running service.
func (*Env) Load ¶
Load reads service.codefly.yaml from dir and adds all declared service-dependencies.
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