Source File
main.go
Belonging Package
golang.org/x/pkgsite/internal/frontend
package frontend
import (
)
SourceFiles []*File
type File struct {
Name string
URL string
}
func ( context.Context, internal.DataSource, *internal.UnitMeta, bool, internal.BuildContext) ( *MainDetails, error) {
defer middleware.ElapsedStat(, "fetchMainDetails")()
, := .GetUnit(, , internal.WithMain, )
if != nil {
return nil,
}
:= getSubdirectories(, .Subdirectories)
if != nil {
return nil,
}
, := getNestedModules(, , , )
if != nil {
return nil,
}
, := readmeContent(, )
if != nil {
return nil,
}
var (
= &dochtml.Parts{}
, []link
[]*File
string
, string
[]internal.BuildContext
)
var *internal.Documentation
if len(.Documentation) > 0 {
= .Documentation[0]
}
if != nil {
= .Synopsis
= .GOOS
= .GOARCH
= .BuildContexts
:= middleware.ElapsedStat(, "DecodePackage")
, := godoc.DecodePackage(.Source)
()
if != nil {
log.Errorf(, "fetchMainDetails(%q, %q, %q): %v", .Path, .ModulePath, .Version, )
return nil, errUnitNotFoundWithoutFetch
}
return nil,
}
if != nil && !errors.Is(, dochtml.ErrTooLarge) {
return nil,
}
for , := range .Links {
= append(, link{Href: .Href, Body: .Text})
}
= middleware.ElapsedStat(, "sourceFiles")
= sourceFiles(, )
()
if .Path != .ModulePath && .IsRedistributable {
, := .GetModuleReadme(, .ModulePath, .Version)
if != nil && !errors.Is(, derrors.NotFound) {
return nil,
}
if == nil {
, := processReadme(, , .SourceInfo)
if != nil {
return nil,
}
= .Links
}
}
, := version.ParseType(.Version)
if != nil {
return nil,
}
:= != version.TypePseudo
:= semver.Major(.Version) != "v0" && == version.TypeRelease
return &MainDetails{
ExpandReadme: ,
Directories: unitDirectories(append(, ...)),
Licenses: transformLicenseMetadata(.Licenses),
CommitTime: absoluteTime(.CommitTime),
Readme: .HTML,
ReadmeOutline: .Outline,
ReadmeLinks: .Links,
DocLinks: ,
ModuleReadmeLinks: ,
DocOutline: .Outline,
DocBody: .Body,
DocSynopsis: ,
GOOS: ,
GOARCH: ,
BuildContexts: ,
SourceFiles: ,
RepositoryURL: .SourceInfo.RepoURL(),
SourceURL: .SourceInfo.DirectoryURL(internal.Suffix(.Path, .ModulePath)),
MobileOutline: .MobileOutline,
NumImports: .NumImports,
ImportedByCount: .NumImportedBy,
IsPackage: .IsPackage(),
ModFileURL: .SourceInfo.ModuleURL() + "/go.mod",
IsTaggedVersion: ,
IsStableVersion: ,
}, nil
}
if len() > 1 && [0].BuildContext() == internal.BuildContextAll {
return [:1]
func ( context.Context, *internal.Unit) ( *Readme, error) {
defer derrors.Wrap(&, "readmeContent(%q, %q, %q)", .Path, .ModulePath, .Version)
defer middleware.ElapsedStat(, "readmeContent")()
if !.IsRedistributable {
return &Readme{}, nil
}
return ProcessReadme(, )
}
const missingDocReplacement = `<p>Documentation is missing.</p>`
func ( context.Context, *internal.Unit, *godoc.Package,
map[string]string) ( *dochtml.Parts, error) {
defer derrors.Wrap(&, "getHTML(%s)", .Path)
if len(.Documentation[0].Source) > 0 {
return renderDocParts(, , , )
}
log.Errorf(, "unit %s (%s@%s) missing documentation source", .Path, .ModulePath, .Version)
return &dochtml.Parts{Body: template.MustParseAndExecuteToHTML(missingDocReplacement)}, nil
![]() |
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. |