ports

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
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

func Allocate(cfg *config.Config, alloc Allocator) error

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

func AppHostPort(cfg *config.Config) int

AppHostPort returns the host port the app container is published on: app-config.host-port when set, otherwise app-config.port.

func Interpolate

func Interpolate(cfg *config.Config, values map[string]string) error

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

func NoAuto() (int, error)

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

func Resolve(cfg *config.Config, alloc Allocator) (map[string]string, error)

Resolve allocates "auto" ports and interpolates the app environment. It is the single entry point a pipeline calls before starting any phase.

func TestEnv

func TestEnv(values map[string]string) map[string]string

TestEnv returns the variables handed to the test runner so features and launcher helpers can reach the app and mocks on this run's ports. Tests run on the host network, hence localhost.

func Values

func Values(cfg *config.Config) map[string]string

Values returns the placeholder table of the run: "mocks.<svc>.<port-key>" for every port of every enabled mock (its default when not configured), plus "app.port" and "app.host-port".

Types

type Allocator

type Allocator func() (int, error)

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.

Jump to

Keyboard shortcuts

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