Skip to content

Reference

Lookup-oriented facts about workspace: every exported symbol, every default value, and what each function does when an argument is wrong.

Godoc — signatures, parameter names and the package comment — is on pkg.go.dev and is not duplicated here. What is here is the behaviour godoc does not state.

The complete exported surface

The package exports eight symbols and nothing else. There is no constructor, no interface, and no package-level state beyond the two variables below.

const DefaultMaxDepth = 100

var ErrNotFound = errors.New("workspace not found: no marker file detected")
var DefaultMarkers = []string{".gtb/manifest.yaml", "go.mod", ".git"}

type Workspace struct {
    Root   string
    Marker string
}

type Option func(*detectConfig)

func WithMaxDepth(depth int) Option
func Detect(fs afero.Fs, startDir string, markers []string, opts ...Option) (*Workspace, error)
func DetectFromCWD(fs afero.Fs, markers []string, opts ...Option) (*Workspace, error)

Defaults at a glance

Setting Default Set with Effect
Maximum parent levels climbed DefaultMaxDepth = 100 WithMaxDepth(n) The start directory plus at most n parents are inspected — n+1 directories in total
Marker list none — it is a required argument pass DefaultMarkers or your own []string Checked in order at each level; first existing entry wins
Filesystem none — it is a required argument afero.NewOsFs() in production, afero.NewMemMapFs() in tests Every existence check is one fs.Stat call
Start directory the process working directory (DetectFromCWD) pass it explicitly to Detect Resolved with filepath.Abs before the walk

There is no configuration file, no environment variable and no global switch. Every input to a detection is an argument to the call.