Documentation
¶
Overview ¶
Package ports resolves dynamic host ports for one gtool run and exposes the resulting values to the app (placeholders) and to the test runner (env).
Index ¶
- Constants
- func Allocate(cfg *config.Config, alloc Allocator) error
- func AppHostPort(cfg *config.Config) int
- func Interpolate(cfg *config.Config, values map[string]string) error
- func NoAuto() (int, error)
- func Resolve(cfg *config.Config, alloc Allocator) (map[string]string, error)
- func TestEnv(values map[string]string) map[string]string
- func Values(cfg *config.Config) map[string]string
- type Allocator
Constants ¶
const Auto = "auto"
Auto is the config value that asks gtool to pick a free host port.
Variables ¶
This section is empty.
Functions ¶
func Allocate ¶
Allocate replaces every "auto" port in mock-config and app-config.host-port with a free port, in place. Explicit ports are left untouched.
func AppHostPort ¶
AppHostPort returns the host port the app container is published on: app-config.host-port when set, otherwise app-config.port.
func Interpolate ¶
Interpolate replaces ${mocks.<svc>.<key>} and ${app.<key>} placeholders in app-config.environment with the run's values, in place. An unknown placeholder is an error: silently passing it through would hand the app a broken address.
func NoAuto ¶
NoAuto is the Allocator for commands run as separate invocations ("services up", then "app start"): nothing persists the ports one of them would pick, so the next one could not find them.
func Resolve ¶
Resolve allocates "auto" ports and interpolates the app environment. It is the single entry point a pipeline calls before starting any phase.
Types ¶
type Allocator ¶
Allocator returns a free host port.
func FreePortAllocator ¶
func FreePortAllocator() Allocator
FreePortAllocator asks the OS for free ports and never returns the same port twice. The port is released before use, so another process could grab it in between; the window is tiny and acceptable for CI isolation.