Copyright 2020 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 godoc is for rendering Go documentation.
package godoc

import (
	
	
	

	
)

var ErrTooLarge = dochtml.ErrTooLarge

type ModuleInfo = dochtml.ModuleInfo
A Package contains package-level information needed to render Go documentation.
encPackage holds the fields of Package that can be directly encoded. If you add any fields, run go generate on this package. If you remove a field, you will have to hand-edit encode_ast.go just to make this package compile before running go generate. Do not remove the field name from the "Fields of" comment, however, or existing encoded data will decode incorrectly. If you rename a field, the field's values in existing encoded data will be lost. Renaming a field is like deleting the old field and adding a new one.
type encPackage struct { // fields that can be directly encoded
	Files              []*File
	ModulePackagePaths map[string]bool
}
A File contains everything needed about a source file to render documentation.
type File struct {
	Name string // full file pathname relative to zip content directory
	AST  *ast.File
}
NewPackage returns a new Package with the given fset and set of module package paths.
func ( *token.FileSet,  map[string]bool) *Package {
	return &Package{
		Fset: ,
		encPackage: encPackage{
			ModulePackagePaths: ,
		},
	}
}
AddFile adds a file to the Package. After it returns, the contents of the ast.File are unsuitable for anything other than the methods of this package.
func ( *Package) ( *ast.File,  bool) {
Don't trim anything from a test file or one in a XXX_test package; it may be part of a playable example.
	if  && !strings.HasSuffix(, "_test.go") && !strings.HasSuffix(.Name.Name, "_test") {
		removeUnusedASTNodes()
	}
	.Files = append(.Files, &File{
		Name: ,
		AST:  ,
	})
}
removeUnusedASTNodes removes parts of the AST not needed for documentation. It doesn't remove unexported consts, vars or types, although it probably could.
func ( *ast.File) {
	var  []ast.Decl
	for ,  := range .Decls {
Remove all unexported functions and function bodies.
			if .Name == nil || !ast.IsExported(.Name.Name) {
				continue
Remove the function body, unless it's an example. The doc contains example bodies.
			if !strings.HasPrefix(.Name.Name, "Example") {
				.Body = nil
			}
		}
		 = append(, )
Don't remove pf.Comments; they may contain Notes.
	.Decls =