Package modfile implements a parser and formatter for go.mod files.
The go.mod syntax is described in https://golang.org/cmd/go/#hdr-The_go_mod_file.
The Parse and ParseLax functions both parse a go.mod file and return an abstract syntax tree. ParseLax ignores unknown statements and may be used to parse go.mod files that may have been developed with newer versions of Go.
The File struct returned by Parse and ParseLax represent an abstract go.mod file. File has several methods like AddNewRequire and DropReplace that can be used to programmatically edit a file.
The Format function formats a File back to a byte slice which can be written to a file.
This section is empty.
AutoQuote returns s or, if quoting is required for s to appear in a go.mod, the quotation of s.
func IsDirectoryPath ¶
IsDirectoryPath reports whether the given path should be interpreted as a directory path. Just like on the go command line, relative paths and rooted paths are directory paths; the rest are module paths.
func ModulePath ¶
ModulePath returns the module path from the gomod file text. If it cannot find a module path, it returns an empty string. It is tolerant of unrelated problems in the go.mod file.
A Directory is a single directory statement.
A WorkFile is the parsed, interpreted form of a go.work file.
Parse 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).