type WorkFile … type Use … // ParseWork parses and returns a go.work file. // // file is the name of the file, used in positions and errors. // // data is the content of the file. // // fix is an optional function that canonicalizes module versions. // If fix is nil, all module versions must be canonical ([module.CanonicalVersion] // must return the same string). func ParseWork(file string, data []byte, fix VersionFixer) (*WorkFile, error) { … } // Cleanup cleans up the file f after any edit operations. // To avoid quadratic behavior, modifications like [WorkFile.DropRequire] // clear the entry but do not remove it from the slice. // Cleanup cleans out all the cleared entries. func (f *WorkFile) Cleanup() { … } func (f *WorkFile) AddGoStmt(version string) error { … } func (f *WorkFile) AddToolchainStmt(name string) error { … } // DropGoStmt deletes the go statement from the file. func (f *WorkFile) DropGoStmt() { … } // DropToolchainStmt deletes the toolchain statement from the file. func (f *WorkFile) DropToolchainStmt() { … } // AddGodebug sets the first godebug line for key to value, // preserving any existing comments for that line and removing all // other godebug lines for key. // // If no line currently exists for key, AddGodebug adds a new line // at the end of the last godebug block. func (f *WorkFile) AddGodebug(key, value string) error { … } // addNewGodebug adds a new godebug key=value line at the end // of the last godebug block, regardless of any existing godebug lines for key. func (f *WorkFile) addNewGodebug(key, value string) { … } func (f *WorkFile) DropGodebug(key string) error { … } func (f *WorkFile) AddUse(diskPath, modulePath string) error { … } func (f *WorkFile) AddNewUse(diskPath, modulePath string) { … } func (f *WorkFile) SetUse(dirs []*Use) { … } func (f *WorkFile) DropUse(path string) error { … } func (f *WorkFile) AddReplace(oldPath, oldVers, newPath, newVers string) error { … } func (f *WorkFile) DropReplace(oldPath, oldVers string) error { … } func (f *WorkFile) SortBlocks() { … } // removeDups removes duplicate replace directives. // // Later replace directives take priority. // // require directives are not de-duplicated. That's left up to higher-level // logic (MVS). // // retract directives are not de-duplicated since comments are // meaningful, and versions may be retracted multiple times. func (f *WorkFile) removeDups() { … }