apply

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package apply brings a project in line with its platformgo.yaml.

A plan compares three things: what generation produces now, what the project has on disk, and what platformgo.lock says was applied before. From that it knows which files to write, which files a newly enabled module needs, and which generated files belong to a module that is gone. That last part is what makes removing a module a one line edit.

Index

Constants

View Source
const AdoptReport = "platformgo.adopt.md"

AdoptReport is the report apply --adopt leaves for a person: the conflicts and what apply did not do yet. It is an input for the work of moving the project, not documentation; delete it when the work is done.

Variables

This section is empty.

Functions

func UnifiedDiff added in v0.9.0

func UnifiedDiff(aName, bName string, a, b []byte) string

UnifiedDiff is a line diff of a and b in the unified format with three lines of context, for people reading a conflict. Files too large to compare cheaply get a one line summary instead.

Types

type Conflict added in v0.9.0

type Conflict struct {
	Path      string
	Disk      []byte // what the project has
	Generated []byte // what platformgo would write
}

Conflict is a file platformgo generates that the project has written itself.

type Plan

type Plan struct {
	Service string
	Modules []string
	Diff    lock.Diff

	Create    []string         // files a module needs and the project does not have yet
	Write     []string         // generated files that differ from the project
	Delete    []string         // generated files of removed modules
	Kept      []string         // generated files of removed modules that were edited by hand
	AddTools  []registry.Tool  // tools of enabled modules missing from go.mod
	DropTools []string         // tools of removed modules still declared in go.mod
	LockStale bool             // platformgo.lock does not match
	Codemods  []codemod.Change // project files rewritten for changes of kit
	Notes     []codemod.Note   // places a person has to change: what codemods could not rewrite

	// Conflicts are generated files the project already has in a version of its own:
	// on disk without the platformgo mark and not recorded in platformgo.lock. apply
	// never overwrites them; Force takes the generated version of one.
	Conflicts []Conflict

	Sqlc gen.SqlcSettings // where sqlc reads and writes, when postgres is enabled
	Jet  gen.JetSettings  // where jet writes, when postgres is enabled
	API  gen.APISettings  // where the proto files are and who writes OpenAPI, when api is enabled
	// contains filtered or unexported fields
}

Plan is what apply would do to a project.

func Build

func Build(dir string) (*Plan, error)

Build reads the project and computes the plan without changing anything.

func (*Plan) Adopt added in v0.9.0

func (p *Plan) Adopt() (created []string, report bool, err error)

Adopt carries out the safe part of the plan for a project that has files of its own, such as a service moving to the platform. It creates the files that do not exist yet and the conflicts the plan forces. Nothing else that exists is changed: writes to existing files, codemods, deletions and go.mod are left for apply once the conflicts are resolved, and the report lists them.

The lock records only what adopt did: the files it wrote join the generated files of the old lock, and the platform version, modules and tools stay as they were. So a later apply still sees the codemods, deletions and tools as pending, and still refuses the conflicts, which the lock does not claim.

func (*Plan) ConflictPaths added in v0.9.0

func (p *Plan) ConflictPaths() []string

ConflictPaths lists the paths of the conflicts.

func (*Plan) Execute

func (p *Plan) Execute() error

Execute carries out the plan: creates, writes, deletes and records the lock. It refuses a plan with conflicts: Force them, or adopt the project with Adopt.

func (*Plan) Force added in v0.9.0

func (p *Plan) Force(paths ...string) error

Force takes the generated version of conflicting files: apply overwrites them. A path that is not a conflict is an error, so a typo does not pass silently.

func (*Plan) Pending

func (p *Plan) Pending() []string

Pending lists every path apply would touch, for messages.

func (*Plan) UpToDate

func (p *Plan) UpToDate() bool

UpToDate reports whether the project already matches its description.

Jump to

Keyboard shortcuts

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