Help us shape the future of Go! Take the 2026 Go Developer Survey

allocator

package
v0.43.15 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package allocator provides resource allocation for git worktrees. It manages port assignment, database name generation, and Redis isolation (via database numbers or key prefixes) to enable parallel development environments.

Index

Constants

This section is empty.

Variables

View Source
var CommonDevPorts = map[int]bool{
	3000: true,
	4000: true,
	4200: true,
	5000: true,
	5173: true,
	5174: true,
	8000: true,
	8080: true,
	8888: true,
}

CommonDevPorts are well-known framework default ports that should be kept free for the proxy to claim. Third-party services (OAuth, Mapbox, Stripe webhooks) are typically whitelisted for these origins — if treeline allocates one, the proxy can't sit on it and the origin-preservation story breaks.

Functions

func CheckPortsListening

func CheckPortsListening(ports []int) bool

CheckPortsListening returns true if at least one of the given ports has an active TCP listener.

func IsCommonDevPort

func IsCommonDevPort(port int) bool

IsCommonDevPort reports whether the port is a well-known framework default that should be kept free for the proxy.

func IsPortFree

func IsPortFree(port int) bool

IsPortFree attempts a TCP listen to verify nothing is bound on the port.

Types

type Allocation

type Allocation struct {
	Project         string
	Worktree        string
	WorktreeName    string
	Branch          string
	Port            int
	Ports           []int
	Database        string
	DatabaseAdapter string
	RedisDB         int
	RedisPrefix     string
	Reused          bool
}

Allocation represents the resources assigned to a worktree including ports, database name, and Redis configuration. Reused is true when an existing allocation was found rather than creating a new one.

func (*Allocation) ToInterpolationMap

func (a *Allocation) ToInterpolationMap() interpolation.Allocation

func (*Allocation) ToRegistryEntry

func (a *Allocation) ToRegistryEntry() registry.Allocation

type Allocator

type Allocator struct {
	UserConfig    *config.UserConfig
	ProjectConfig *config.ProjectConfig
	Registry      *registry.Registry
}

Allocator manages resource allocation using user and project configuration. It tracks used resources via the registry to avoid conflicts between worktrees.

func (*Allocator) Allocate

func (al *Allocator) Allocate(worktreePath, worktreeName string, mainWorktree bool, branch ...string) (*Allocation, error)

Allocate returns an allocation for the given worktree. If an existing allocation is found in the registry, it is reused (idempotent). Otherwise a new allocation is created. When mainWorktree is true, base resources (port_base, template DB, no redis prefix) are returned directly. Branch is optional — when provided, enables branch-specific port reservations.

func (*Allocator) BuildRedisURL

func (al *Allocator) BuildRedisURL(alloc *Allocation) string

Jump to

Keyboard shortcuts

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