// ReadModFile reads and parses the mod file at gomod. ReadModFile properly applies the // overlay, locks the file while reading, and applies fix, if applicable. func ReadModFile(gomod string, fix modfile.VersionFixer) (data []byte, f *modfile.File, err error) { … } type modFileIndex … type requireMeta … type modPruning … const pruned … const unpruned … const workspace … func (p modPruning) String() string { … } func pruningForGoVersion(goVersion string) modPruning { … } // CheckAllowed returns an error equivalent to ErrDisallowed if m is excluded by // the main module's go.mod or retracted by its author. Most version queries use // this to filter out versions that should not be used. func CheckAllowed(ctx context.Context, m module.Version) error { … } var ErrDisallowed … // CheckExclusions returns an error equivalent to ErrDisallowed if module m is // excluded by the main module's go.mod file. func CheckExclusions(ctx context.Context, m module.Version) error { … } var errExcluded … type excludedError … func (e *excludedError) Error() string { … } func (e *excludedError) Is(err error) bool { … } // CheckRetractions returns an error if module m has been retracted by // its author. func CheckRetractions(ctx context.Context, m module.Version) (err error) { … } type ModuleRetractedError … func (e *ModuleRetractedError) Error() string { … } func (e *ModuleRetractedError) Is(err error) bool { … } type retractionLoadingError … func (e *retractionLoadingError) Error() string { … } func (e *retractionLoadingError) Unwrap() error { … } // ShortMessage returns a string from go.mod (for example, a retraction // rationale or deprecation message) that is safe to print in a terminal. // // If the given string is empty, ShortMessage returns the given default. If the // given string is too long or contains non-printable characters, ShortMessage // returns a hard-coded string. func ShortMessage(message, emptyDefault string) string { … } // CheckDeprecation returns a deprecation message from the go.mod file of the // latest version of the given module. Deprecation messages are comments // before or on the same line as the module directives that start with // "Deprecated:" and run until the end of the paragraph. // // CheckDeprecation returns an error if the message can't be loaded. // CheckDeprecation returns "", nil if there is no deprecation message. func CheckDeprecation(ctx context.Context, m module.Version) (deprecation string, err error) { … } func replacement(mod module.Version, replace map[module.Version]module.Version) (fromVersion string, to module.Version, ok bool) { … } // Replacement returns the replacement for mod, if any. If the path in the // module.Version is relative it's relative to the single main module outside // workspace mode, or the workspace's directory in workspace mode. func Replacement(mod module.Version) module.Version { … } // replacementFrom returns the replacement for mod, if any, the modroot of the replacement if it appeared in a go.mod, // and the source of the replacement. The replacement is relative to the go.work or go.mod file it appears in. func replacementFrom(mod module.Version) (r module.Version, modroot string, fromFile string) { … } func replaceRelativeTo() string { … } // canonicalizeReplacePath ensures that relative, on-disk, replaced module paths // are relative to the workspace directory (in workspace mode) or to the module's // directory (in module mode, as they already are). func canonicalizeReplacePath(r module.Version, modRoot string) module.Version { … } // resolveReplacement returns the module actually used to load the source code // for m: either m itself, or the replacement for m (iff m is replaced). // It also returns the modroot of the module providing the replacement if // one was found. func resolveReplacement(m module.Version) module.Version { … } func toReplaceMap(replacements []*modfile.Replace) map[module.Version]module.Version { … } // indexModFile rebuilds the index of modFile. // If modFile has been changed since it was first read, // modFile.Cleanup must be called before indexModFile. func indexModFile(data []byte, modFile *modfile.File, mod module.Version, needsFix bool) *modFileIndex { … } // modFileIsDirty reports whether the go.mod file differs meaningfully // from what was indexed. // If modFile has been changed (even cosmetically) since it was first read, // modFile.Cleanup must be called before modFileIsDirty. func (i *modFileIndex) modFileIsDirty(modFile *modfile.File) bool { … } var rawGoVersion … type modFileSummary … type retraction … // goModSummary returns a summary of the go.mod file for module m, // taking into account any replacements for m, exclusions of its dependencies, // and/or vendoring. // // m must be a version in the module graph, reachable from the Target module. // In readonly mode, the go.sum file must contain an entry for m's go.mod file // (or its replacement). goModSummary must not be called for the Target module // itself, as its requirements may change. Use rawGoModSummary for other // module versions. // // The caller must not modify the returned summary. func goModSummary(m module.Version) (*modFileSummary, error) { … } // rawGoModSummary returns a new summary of the go.mod file for module m, // ignoring all replacements that may apply to m and excludes that may apply to // its dependencies. // // rawGoModSummary cannot be used on the main module outside of workspace mode. // The modFileSummary can still be used for retractions and deprecations // even if a TooNewError is returned. func rawGoModSummary(m module.Version) (*modFileSummary, error) { … } var rawGoModSummaryCache … // rawGoModData returns the content of the go.mod file for module m, ignoring // all replacements that may apply to m. // // rawGoModData cannot be used on the main module outside of workspace mode. // // Unlike rawGoModSummary, rawGoModData does not cache its results in memory. // Use rawGoModSummary instead unless you specifically need these bytes. func rawGoModData(m module.Version) (name string, data []byte, err error) { … } // queryLatestVersionIgnoringRetractions looks up the latest version of the // module with the given path without considering retracted or excluded // versions. // // If all versions of the module are replaced, // queryLatestVersionIgnoringRetractions returns the replacement without making // a query. // // If the queried latest version is replaced, // queryLatestVersionIgnoringRetractions returns the replacement. func queryLatestVersionIgnoringRetractions(ctx context.Context, path string) (latest module.Version, err error) { … } var latestVersionIgnoringRetractionsCache … // ToDirectoryPath adds a prefix if necessary so that path in unambiguously // an absolute path or a relative path starting with a '.' or '..' // path component. func ToDirectoryPath(path string) string { … }