// Main bool // is this the main module?
// Indirect bool // is this module only an indirect dependency of main module?
// Dir string // directory holding files for this module, if any
-// GoMod string // path to go.mod file for this module, if any
+// GoMod string // path to go.mod file used when loading this module, if any
// GoVersion string // go version used in module
// Error *ModuleError // error loading module
// }
// Err string // the error itself
// }
//
+// The file GoMod refers to may be outside the module directory if the
+// module is in the module cache or if the -modfile flag is used.
+//
// The default output is to print the module path and then
// information about the version and replacement if any.
// For example, 'go list -m all' might print:
Main bool // is this the main module?
Indirect bool // is this module only an indirect dependency of main module?
Dir string // directory holding files for this module, if any
- GoMod string // path to go.mod file for this module, if any
+ GoMod string // path to go.mod file used when loading this module, if any
GoVersion string // go version used in module
Error *ModuleError // error loading module
}
Err string // the error itself
}
+The file GoMod refers to may be outside the module directory if the
+module is in the module cache or if the -modfile flag is used.
+
The default output is to print the module path and then
information about the version and replacement if any.
For example, 'go list -m all' might print:
}
if HasModRoot() {
info.Dir = ModRoot()
- info.GoMod = filepath.Join(info.Dir, "go.mod")
+ info.GoMod = ModFilePath()
if modFile.Go != nil {
info.GoVersion = modFile.Go.Version
}
go mod init example.com/m
grep example.com/m go.alt.mod
+# 'go env GOMOD' should print the path to the real file.
+# 'go env' does not recognize the '-modfile' flag.
+go env GOMOD
+stdout '^\$WORK[/\\]gopath[/\\]src[/\\]go.mod$'
+
+# 'go list -m' should print the effective go.mod file as GoMod though.
+go list -m -f '{{.GoMod}}'
+stdout '^go.alt.mod$'
+
# go mod edit should operate on the alternate file
go mod edit -require rsc.io/quote@v1.5.2
grep rsc.io/quote go.alt.mod