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 ¶
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
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 (*Plan) Adopt ¶ added in v0.9.0
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
ConflictPaths lists the paths of the conflicts.
func (*Plan) Execute ¶
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
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.