wspath

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package wspath defines the typed coordination key for a workspace file. A Path is an absolute, syntactically clean filesystem path that the coordination layer uses as a hold key, hold-release key, and the value carried in coord.File. The substrate (holds) and the domain (coord, swarm, dispatch) agree on the same key by construction; no caller hand-rolls path normalization.

Paths are produced by exactly two constructors: New, which wraps an already-absolute path, and NewRelative, which joins a workspace- relative path onto an absolute workspace root and rejects any result that escapes the root via "..". Both return ErrInvalid on bad input rather than producing a Path that fails downstream.

The package re-exports as coord.Path via a type alias so the public vocabulary stays "coord.Path" while the implementation stays dependency-free. Holds depends on wspath directly.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("wspath: invalid path")

ErrInvalid wraps every constructor failure. Callers can errors.Is against it to distinguish bad input from substrate errors.

Functions

This section is empty.

Types

type Path

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

Path is the typed coordination key for a workspace file. The zero value is invalid — use IsZero to test for it.

func Must

func Must(abs string) Path

Must wraps New and panics on error. Intended for tests and for programs whose input is a compile-time-known absolute path; every other caller should use New and handle ErrInvalid.

func New

func New(abs string) (Path, error)

New wraps an absolute filesystem path in a Path. The input is passed through filepath.Clean, so "/a//b/", "/a/./b", and "/a/b" all produce the same canonical Path. Returns an ErrInvalid-wrapped error when input is empty or not absolute.

func NewRelative

func NewRelative(workspaceDir, rel string) (Path, error)

NewRelative joins workspaceDir and rel into a Path anchored inside workspaceDir. workspaceDir must itself be absolute. The cleaned join must lie at or under workspaceDir; a rel that escapes via ".." is rejected. rel must not be absolute (use New for that path).

func (Path) AsAbsolute

func (p Path) AsAbsolute() string

AsAbsolute returns the canonical absolute path string.

func (Path) AsKey

func (p Path) AsKey() string

AsKey returns the coordination-key form of the path. Currently equal to AsAbsolute; kept distinct so a future schema change to the hold-bucket key format can stay invisible to callers.

func (Path) IsZero

func (p Path) IsZero() bool

IsZero reports whether p is the zero Path. The zero value is invalid and must not be passed across coordination seams.

func (Path) String

func (p Path) String() string

String implements fmt.Stringer; returns AsAbsolute.

Jump to

Keyboard shortcuts

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