Source File
render.go
Belonging Package
golang.org/x/pkgsite/internal/godoc
package godoc
import (
)
const (
megabyte = 1000 * 1000
maxImportsPerPackage = 2000
DocTooLargeReplacement = `<p>Documentation is too large to display.</p>`
)
var MaxDocumentationHTML = 20 * megabyte
defer derrors.Wrap(&, "godoc.Package.DocInfo(%q, %q, %q)", .ModulePath, .ResolvedVersion, )
.renderCalled = true
, := .docPackage(, )
if != nil {
return "", nil, nil,
}
, = dochtml.GetSymbols(, .Fset)
if != nil {
return "", nil, nil,
}
return doc.Synopsis(.Doc), .Imports, , nil
}
func ( *Package) ( string, *ModuleInfo) ( *doc.Package, error) {
defer derrors.Wrap(&, "docPackage(%q, %q, %q)", , .ModulePath, .ResolvedVersion)
:= path.Join(.ModulePath, )
if .ModulePath == stdlib.ModulePath {
=
}
if .ModulePackages == nil {
.ModulePackages = .ModulePackagePaths
}
var , bool
if .ModulePath == stdlib.ModulePath && == "builtin" {
= true
= true
}
var doc.Mode
if {
|= doc.AllDecls
}
var []*ast.File
for , := range .Files {
= append(, .AST)
}
, := doc.NewFromFiles(.Fset, , , )
if != nil {
return nil, fmt.Errorf("doc.NewFromFiles: %v", )
}
if .ImportPath != {
panic(fmt.Errorf("internal error: *doc.Package has an unexpected import path (%q != %q)", .ImportPath, ))
}
if {
for , := range .Types {
.Consts, .Consts = append(.Consts, .Consts...), nil
.Vars, .Vars = append(.Vars, .Vars...), nil
.Funcs, .Funcs = append(.Funcs, .Funcs...), nil
}
sort.Slice(.Funcs, func(, int) bool { return .Funcs[].Name < .Funcs[].Name })
}
if len(.Imports) > maxImportsPerPackage {
return nil, fmt.Errorf("%d imports found package %q; exceeds limit %d for maxImportsPerPackage", len(.Imports), , maxImportsPerPackage)
}
return , nil
}
func ( *Package) ( string, *source.Info, *ModuleInfo,
map[string]string) dochtml.RenderOptions {
:= func( ast.Node) string {
if == nil {
return ""
}
:= .Fset.Position(.Pos())
if .Line == 0 { // invalid Position
return ""
}
return .LineURL(path.Join(, .Filename), .Line)
}
:= func( string) string {
if == nil {
return ""
}
return .FileURL(path.Join(, ))
}
return dochtml.RenderOptions{
FileLinkFunc: ,
SourceLinkFunc: ,
ModInfo: ,
SinceVersionFunc: sinceVersionFunc(.ModulePath, ),
Limit: int64(MaxDocumentationHTML),
}
}
, := stdlib.TagForVersion()
return
}
return
}
}
func ( *Package) ( context.Context, string,
*source.Info, *ModuleInfo, map[string]string) ( *dochtml.Parts, error) {
.renderCalled = true
, := .docPackage(, )
if != nil {
return nil,
}
:= .renderOptions(, , , )
, := dochtml.Render(, .Fset, , )
if errors.Is(, ErrTooLarge) {
return &dochtml.Parts{Body: template.MustParseAndExecuteToHTML(DocTooLargeReplacement)}, nil
}
if != nil {
return nil, fmt.Errorf("dochtml.Render: %v", )
}
return , nil
}
func ( context.Context, *internal.Unit) ( *dochtml.Parts, error) {
, := DecodePackage(.Documentation[0].Source)
if != nil {
return nil,
}
:= &ModuleInfo{
ModulePath: .ModulePath,
ResolvedVersion: .Version,
ModulePackages: nil, // will be provided by docPkg
}
var string
if .ModulePath == stdlib.ModulePath {
= .Path
} else if .Path != .ModulePath {
= .Path[len(.ModulePath)+1:]
}
return .Render(, , .SourceInfo, , 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. |