Copyright 2019 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 frontend

import (
	
	
	
	

	
	
	
	
)
ImportsDetails contains information for a package's imports.
ExternalImports is the collection of package imports that are not in the Go standard library and are not part of the same module
InternalImports is an array of packages representing the package's imports that are part of the same module.
StdLib is an array of packages representing the package's imports that are in the Go standard library.
fetchImportsDetails fetches imports for the package version specified by pkgPath, modulePath and version from the database and returns a ImportsDetails.
func ( context.Context,  internal.DataSource, , ,  string) ( *ImportsDetails,  error) {
	,  := .GetUnit(, &internal.UnitMeta{
		Path: ,
		ModuleInfo: internal.ModuleInfo{
			ModulePath: ,
			Version:    ,
		},
	}, internal.WithImports, internal.BuildContext{})
	if  != nil {
		return nil, 
	}

	var , ,  []string
	for ,  := range .Imports {
		if stdlib.Contains() {
			 = append(, )
		} else if strings.HasPrefix(+"/", +"/") {
			 = append(, )
		} else {
			 = append(, )
		}
	}

	return &ImportsDetails{
		ModulePath:      ,
		ExternalImports: ,
		InternalImports: ,
		StdLib:          ,
	}, nil
}
ImportedByDetails contains information for the collection of packages that import a given package.
ModulePath is the module path for the package referenced on this page.
ImportedBy is the collection of packages that import the given package and are not part of the same module. They are organized into a tree of sections by prefix.
NumImportedByDisplay is the display text at the top of the imported by tab section, which shows the imported by count and package limit.
Total is the total number of importers.
importedByLimit is the maximum number of importers displayed on the imported by page. Variable for testing.
	importedByLimit = 20001
)
fetchImportedByDetails fetches importers for the package version specified by path and version from the database and returns a ImportedByDetails.
func ( context.Context,  internal.DataSource, ,  string) (*ImportedByDetails, error) {
	,  := .(*postgres.DB)
The proxydatasource does not support the imported by page.
		return nil, proxydatasourceNotSupportedErr()
	}

	,  := .GetImportedBy(, , , importedByLimit)
	if  != nil {
		return nil, 
	}
	 := len()
	,  := .GetImportedByCount(, , )
	if  != nil {
		return nil, 
	}
numImportedBySearch should never be greater than numImportedBy. If that happens, log an error so that we can debug, but continue with generating the page fo the user.
		log.Errorf(, "search_documents.num_imported_by > numImportedBy from imports unique, which shouldn't happen: %d", )
	}

	if  >= importedByLimit {
		 = [:importedByLimit-1]
	}
	 := Sections(, nextPrefixAccount)
Display the number of importers, taking into account the number we actually retrieved, the limit on that number, and the imported-by count in the search_documents table.
	var (
		 string
		 = "package"
	)
	if  > 1 {
		 = "packages"
	}
If there are more importers than the limit, and the search number is greater, use the search number and indicate that we're displaying fewer.
	case  >= importedByLimit &&  > :
If we've exceeded the limit but the search number is smaller, we don't know the true number, so say so.
	case  >= importedByLimit:
If we haven't exceeded the limit and we have more than the search number, then display both numbers so users coming from the search page won't see a mismatch.
	case  > :
Otherwise, we have all the packages, and the search number is either wrong (perhaps it hasn't been recomputed yet) or it is the same as the retrieved number. In that case, just display the retrieved number.
	default:
		 = strconv.Itoa()
	}
	return &ImportedByDetails{
		ModulePath:           ,
		ImportedBy:           ,
		NumImportedByDisplay: ,
		Total:                ,
	}, nil