ports

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ports provides port-holder identification utilities for the nSelf CLI. It augments the raw TCP port probing in internal/docker with process-level information so that conflict error messages name the offending process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatConflictMessage

func FormatConflictMessage(port int, holder *Holder) string

FormatConflictMessage formats a human-readable port conflict error message. Example: "port 5432 is held by postgres (pid 1234) — stop it or change POSTGRES_PORT" If holder is nil (port is free or detection unavailable), the message omits holder info.

Types

type Holder

type Holder struct {
	PID     int
	Name    string // process name (short, e.g. "postgres")
	Command string // full command line
	IsOurs  bool   // true if the holder is one of our own Docker containers
}

Holder describes the process that is listening on a TCP port.

func WhoHoldsPort

func WhoHoldsPort(port int) (*Holder, error)

WhoHoldsPort returns the process holding the given TCP port. Returns nil (not an error) if the port is free or if holder detection is unavailable on the current platform (e.g. lsof/ss not installed). A non-nil error is returned only for unexpected failures after a holder was partially identified.

Jump to

Keyboard shortcuts

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