goworkspace

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package goworkspace builds the synthetic go.work Kivgraph uses to load every registered Go module in a single go/packages universe.

The file is written outside every repository, under the configured state directory. Kivgraph never writes a go.work inside an indexed repository.

Index

Constants

This section is empty.

Variables

View Source
var ErrGoVersionUnsupported = errors.New("registered Go module requires a newer Go language version than this build supports")

ErrGoVersionUnsupported reports a registered module whose language version is newer than the one this build can type-check.

View Source
var ErrNoModules = errors.New("no registered repository declares a Go module")

ErrNoModules reports that no registered repository declares a Go module.

View Source
var ErrRepositoryTarget = errors.New("synthetic go.work path is inside a registered repository")

ErrRepositoryTarget reports a synthetic workspace path inside a repository.

Functions

func LanguageVersion

func LanguageVersion() string

LanguageVersion is the `major.minor` language version this build can type check, derived from the toolchain that compiled it.

Types

type Conflict

type Conflict struct {
	Kind         ConflictKind
	Subject      string
	Repositories []string
	Details      []string
}

Conflict is a fact deliberately excluded because it cannot be decided.

type ConflictKind

type ConflictKind string

ConflictKind classifies a fact excluded from the synthetic workspace.

const (
	// AmbiguousModule marks one module path declared by several repositories.
	AmbiguousModule ConflictKind = "AMBIGUOUS_MODULE_PROVIDER"
	// ReplaceConflict marks one replaced path with incompatible targets.
	ReplaceConflict ConflictKind = "MODULE_REPLACE_CONFLICT"
)

type Module

type Module struct {
	Repository   string
	ModulePath   string
	RootPath     string
	ManifestPath string
	GoVersion    string
	// PackagePatterns are the discovered package paths passed to go/packages.
	PackagePatterns []string
	// Reaches are the module paths this module requires or replaces. Only
	// the ones a registered repository provides matter, and they decide
	// which modules must share a workspace.
	Reaches []string
	// WorkspaceMembers are the module paths bound together by a go.work of
	// the indexed repository that lists this module, this one included.
	// That file is a fact of the repository, so its grouping is preserved
	// and its members always load through a workspace.
	WorkspaceMembers []string
}

Module is one Go module included in the synthetic workspace.

type Options

type Options struct {
	// GoVersion overrides the version derived from the module manifests.
	GoVersion string
	// MaximumGoVersion is the highest language version the caller can type
	// check. Empty means the version of the toolchain that built this
	// binary, which is the only honest default: go/types is linked in, so
	// the workspace must never select a toolchain whose sources it cannot
	// read. Loading a newer module would fail deep inside the standard
	// library instead of naming the repository that requires it.
	MaximumGoVersion string
}

Options tunes how the plan is built.

type Plan

type Plan struct {
	GoVersion string
	Modules   []Module
	Replaces  []Replacement
	Conflicts []Conflict
}

Plan is the deterministic content of one synthetic workspace.

func BuildPlan

func BuildPlan(ctx context.Context, repositories []workspace.Repository, options Options) (Plan, error)

BuildPlan discovers every Go module of the registered repositories and composes the workspace content without writing anything.

Ambiguous module paths and incompatible replacements are excluded and reported: go itself rejects a workspace with two directories providing the same module, and a replacement Kivgraph cannot decide must never be guessed.

func (Plan) Partition

func (plan Plan) Partition() []Plan

Partition splits the plan into the independent workspaces it really needs.

A go.work resolves one build list for every module it uses, so unrelated repositories end up sharing a minimum version selection: a dependency bumped in one of them changes the versions selected for all the others, and a version no repository downloaded on its own breaks every load at once. Two modules only need the same workspace when one can reach the other: a requirement or a replacement naming a registered module, or a go.work of the indexed repository that already binds them together. Everything else is loaded exactly as its own toolchain would load it.

The returned plans are ordered by their first module path, and a plan with a single module that reaches nothing keeps its own manifest as the only truth: callers load it in module mode, with no workspace at all.

func (Plan) Render

func (plan Plan) Render() ([]byte, error)

Render produces the canonical go.work bytes for this plan.

type Replacement

type Replacement struct {
	OldPath    string
	OldVersion string
	NewPath    string
	NewVersion string
}

Replacement is a replace directive promoted to the synthetic workspace.

type Result

type Result struct {
	Path    string
	Bytes   int
	Changed bool
}

Result reports what a write did.

func Write

func Write(ctx context.Context, path string, plan Plan, repositories []workspace.Repository) (Result, error)

Write renders the plan and installs it atomically at path.

The path is rejected when it falls inside any registered repository, so a misconfiguration cannot make Kivgraph write a go.work into indexed code.

Jump to

Keyboard shortcuts

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