Source File
unit.go
Belonging Package
golang.org/x/pkgsite/internal/frontend
package frontend
import (
)
type UnitPage struct {
Details interface{}
}
func ( *Server) ( context.Context, http.ResponseWriter, *http.Request,
internal.DataSource, *urlPathInfo) ( error) {
defer derrors.Wrap(&, "serveUnitPage(ctx, w, r, ds, %v)", )
defer middleware.ElapsedStat(, "serveUnitPage")()
:= .FormValue("tab")
= tabMain
if , := unitTabLookup[]; ! {
http.Redirect(, , .URL.Path, http.StatusFound)
return nil
}
, := .GetUnitMeta(, .fullPath, .modulePath, .requestedVersion)
if != nil {
if !errors.Is(, derrors.NotFound) {
return
}
return .servePathNotFoundPage(, , , .fullPath, .modulePath, .requestedVersion)
}
:= internal.BuildContext{GOOS: .FormValue("GOOS"), GOARCH: .FormValue("GOARCH")}
, := fetchDetailsForUnit(, , , , , )
if != nil {
return
}
if .serveStats && .FormValue("m") == "json" {
, := json.Marshal()
if != nil {
return fmt.Errorf("json.Marshal: %v", )
}
if , := .Write(); != nil {
return fmt.Errorf("w.Write: %v", )
}
return nil
}
recordVersionTypeMetric(, .requestedVersion)
go func() {
, := context.WithTimeout(context.Background(), 1*time.Minute)
defer ()
log.Infof(, "serveUnitPage: Scheduling %q@%q to be fetched", .ModulePath, .requestedVersion)
if , := .queue.ScheduleFetch(, .ModulePath, .requestedVersion, "", false); != nil {
log.Errorf(, "serveUnitPage(%q): scheduling fetch for %q@%q: %v",
.URL.Path, .ModulePath, .requestedVersion, )
}
}()
}
var *internal.UnitMeta
if .modulePath == internal.UnknownModulePath && .requestedVersion == internal.LatestVersion {
=
}
:= .GetLatestInfo(, .Path, .ModulePath, )
var string
, = cookie.Extract(, , cookie.AlternativeModuleFlash)
log.Errorf(, "extracting AlternativeModuleFlash cookie: %v", )
}
:= unitTabLookup[]
:= pageTitle()
:= .newBasePage(, )
.AllowWideContent = true
:= linkVersion(.Version, .ModulePath)
:= UnitPage{
basePage: ,
Unit: ,
Breadcrumb: displayBreadcrumb(, .requestedVersion),
Title: ,
SelectedTab: ,
URLPath: constructUnitURL(.Path, .ModulePath, .requestedVersion),
CanonicalURLPath: canonicalURLPath(),
DisplayVersion: displayVersion(.Version, .ModulePath),
LinkVersion: ,
LatestURL: constructUnitURL(.Path, .ModulePath, internal.LatestVersion),
LatestMinorClass: latestMinorClass(, ),
LatestMajorVersionURL: .MajorUnitPath,
PageLabels: pageLabels(),
PageType: pageType(),
RedirectedFromPath: ,
}
:= internal.MajorVersionForModule(.MajorModulePath)
if != "" && != internal.MajorVersionForModule(.ModulePath) {
.LatestMajorVersion =
}
.Details =
, := .(*MainDetails)
if {
.MetaDescription = metaDescription(strconv.Itoa(.ImportedByCount))
}
.servePage(, , .TemplateName, )
return nil
}
func ( string, internal.LatestInfo) string {
:= "DetailsHeader-badge"
switch {
case .MinorVersion == "":
+= "--unknown"
case .MinorVersion == && !.UnitExistsAtMinor:
+= "--notAtLatest"
case .MinorVersion == :
+= "--latest"
default:
+= "--goToLatest"
}
return
}
func ( string) safehtml.HTML {
if == "" {
return safehtml.HTML{}
}
return safehtml.HTMLConcat(
uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract(`<meta name="Description" content="`),
safehtml.HTMLEscaped(),
uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract(`">`),
)
}
func ( string, *internal.UnitMeta) bool {
if == tabLicenses && !.IsRedistributable {
return false
}
if !.IsPackage() && ( == tabImports || == tabImportedBy) {
return false
}
return true
}
func (, , string) string {
if == internal.LatestVersion {
return "/" +
}
:= linkVersion(, )
if == || == stdlib.ModulePath {
return fmt.Sprintf("/%s@%s", , )
}
return fmt.Sprintf("/%s@%s/%s", , , strings.TrimPrefix(, +"/"))
}
func ( *internal.UnitMeta) string {
return constructUnitURL(.Path, .ModulePath, linkVersion(.Version, .ModulePath))
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |