Documentation ¶
Overview ¶
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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var GoVersionRE = lazyregexp.New(`^([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
Functions ¶
func AutoQuote ¶
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.
Types ¶
type Directory ¶
type Directory struct { DiskPath string // TODO(matloob): Replace uses module.Version for new. Do that here? ModulePath string // Module path in the comment. Syntax *modfile.Line }
A Directory is a single directory statement.
type WorkFile ¶
type WorkFile struct { Go *modfile.Go Directory []*Directory Replace []*modfile.Replace Syntax *modfile.FileSyntax }
A WorkFile is the parsed, interpreted form of a go.work file.
func ParseWork ¶
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).