Copyright 2021 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package internal

import (
	
	

	
	
)
LatestModuleVersions describes the latest versions of a module. It also holds the go.mod file of the raw latest version, which establishes whether the module is deprecated, and what versions are retracted.
type LatestModuleVersions struct {
	ModulePath         string
	RawVersion         string        // ignoring retractions
	CookedVersion      string        // considering retractions
	GoodVersion        string        // successfully processed
	GoModFile          *modfile.File // of raw
	Deprecated         bool
	deprecationComment string
}

func (, , ,  string,  []byte) (*LatestModuleVersions, error) {
	,  := modfile.ParseLax(fmt.Sprintf("%s@%s/go.mod", , ), , nil)
	if  != nil {
		return nil, 
	}

	,  := isDeprecated()
	return &LatestModuleVersions{
		ModulePath:         ,
		RawVersion:         ,
		CookedVersion:      ,
		GoodVersion:        ,
		GoModFile:          ,
		Deprecated:         ,
		deprecationComment: ,
	}, nil
}
isDeprecated reports whether the go.mod deprecates this module. It looks for "Deprecated" comments in the line comments before and next to the module declaration. If it finds one, it returns true along with the text after "Deprecated:". Otherwise it returns false, "".
func ( *modfile.File) (bool, string) {
	const  = "Deprecated:"

	if .Module == nil {
		return false, ""
	}
	for ,  := range append(.Module.Syntax.Before, .Module.Syntax.Suffix...) {
		 := strings.TrimSpace(strings.TrimPrefix(.Token, "//"))
		if strings.HasPrefix(, ) {
			return true, strings.TrimSpace([len():])
		}
	}
	return false, ""
}
PopulateModuleInfo uses the LatestModuleVersions to populate fields of the given module.
IsRetracted reports whether the version is retracted according to the go.mod file in the receiver.
func ( *LatestModuleVersions) ( string) bool {
	,  := isRetracted(.GoModFile, )
	return 
}
isRetracted reports whether the go.mod file retracts the version. If so, it returns true along with the rationale for the retraction.
func ( *modfile.File,  string) (bool, string) {
	for ,  := range .Retract {
		if semver.Compare(, .Low) >= 0 && semver.Compare(, .High) <= 0 {
			return true, .Rationale
		}
	}
	return false, ""