isolation

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package isolation resolves worktree-specific local runtime resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAddr added in v0.82.0

func ListenAddr(projectDir, fallback string) (string, error)

ListenAddr is the one call a hand-written main needs to bind where `gofastr dev`, a PaaS, or worktree isolation says: it resolves isolation for projectDir, reads $PORT (a bare port "8088" or a host:port "localhost:8088", both of which `gofastr dev` and PaaS runtimes inject), falls back to fallback when $PORT is empty, and returns the address with isolation's port remap applied. Pass the result to App.Start or http.ListenAndServe.

Types

type Config

type Config struct {
	Enabled  bool
	Mode     string
	Port     PortConfig
	Database DatabaseConfig
	Services map[string]int
	Env      map[string]string
}

Config describes local resource isolation.

type DatabaseConfig

type DatabaseConfig struct {
	Strategy string
}

DatabaseConfig controls default DSN rewriting.

type PortConfig

type PortConfig struct {
	Strategy string
	Offset   int
	Range    int
	Scan     int
}

PortConfig controls deterministic port remapping.

type Runtime

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

Runtime is the resolved isolation context for a project.

func Resolve

func Resolve(projectDir string) (*Runtime, error)

Resolve loads isolation config for projectDir and returns its runtime.

func (*Runtime) Active

func (r *Runtime) Active() bool

Active reports whether isolation applies to this runtime.

func (*Runtime) Addr

func (r *Runtime) Addr(addr string) (string, error)

Addr returns addr with its port remapped when isolation is active. It first normalizes a bare numeric port to ":<port>" so a PaaS-injected $PORT (e.g. "8088" from Heroku/Render/Railway/Cloud Run) is a valid http.Server address.

func (*Runtime) Database

func (r *Runtime) Database(driver, dsn string) (string, string, error)

Database returns an isolated database driver and DSN when isolation is active.

func (*Runtime) Env

func (r *Runtime) Env(env []string) []string

Env returns env with configured local resources isolated. Entries from the project's isolation.env are limited to template values (ports, id, project dir) for variables the operator has NOT set: an operator export always wins, and process-shaping names never come from the file (loadConfig already dropped both, this is the second half of the same rule). GOFASTR_ISOLATION_REWRITE governs only the PORT and DATABASE_URL remaps.

func (*Runtime) ID

func (r *Runtime) ID() string

ID returns the stable isolation identifier.

Jump to

Keyboard shortcuts

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