pkgsite: Index | Files | Directories

package godoc

import ""

Package godoc is for rendering Go documentation.


Package Files

encode.go encode_ast.gen.go godoc.go render.go


const (

    // Exported for tests.
    DocTooLargeReplacement = `<p>Documentation is too large to display.</p>`


var ErrInvalidEncodingType = fmt.Errorf("want initial bytes to be %q or %q but they aren't", gobEncodingType, fastEncodingType)

ErrInvalidEncodingType is returned when the data to DecodePackage has an invalid encoding type.

var ErrTooLarge = dochtml.ErrTooLarge
var MaxDocumentationHTML = 20 * megabyte

MaxDocumentationHTML is a limit on the rendered documentation HTML size.

The current limit of is based on the largest packages that has encountered. See

It is a variable for testing.

var TypesToGenerate = []interface{}{&encPackage{}}

Used by the gen program to generate encodings for unexported types.

func RenderPartsFromUnit Uses

func RenderPartsFromUnit(ctx context.Context, u *internal.Unit) (_ *dochtml.Parts, err error)

RenderPartsFromUnit is a convenience function that first decodes the source in the unit, which must exist, and then calls RenderParts.

type File Uses

type File struct {
    Name string // full file pathname relative to zip content directory
    AST  *ast.File
    // The following fields are only for encoding and decoding. They are public
    // only because gob requires them to be. Clients should ignore them.
    UnresolvedNums []int       `codec:"-"` // used to handle sharing of unresolved identifiers
    ScopeItems     []scopeItem `codec:"-"` // sorted by name for deterministic encoding

A File contains everything needed about a source file to render documentation.

type ModuleInfo Uses

type ModuleInfo = dochtml.ModuleInfo

type Package Uses

type Package struct {
    Fset *token.FileSet
    // contains filtered or unexported fields

A Package contains package-level information needed to render Go documentation.

func DecodePackage Uses

func DecodePackage(data []byte) (_ *Package, err error)

DecodPackage decodes a byte slice encoded with Package.Encode into a Package.

func NewPackage Uses

func NewPackage(fset *token.FileSet, goos, goarch string, modPaths map[string]bool) *Package

NewPackage returns a new Package with the given fset and set of module package paths.

func (*Package) AddFile Uses

func (p *Package) AddFile(f *ast.File, removeNodes bool)

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) Encode Uses

func (p *Package) Encode(ctx context.Context) (_ []byte, err error)

Encode encodes a Package into a byte slice. During its operation, Encode modifies the AST, but it restores it to a state suitable for rendering before it returns.

func (*Package) Render Uses

func (p *Package) Render(ctx context.Context, innerPath string, sourceInfo *source.Info, modInfo *ModuleInfo, goos, goarch string) (synopsis string, imports []string, html safehtml.HTML, err error)

Render renders the documentation for the package. Rendering destroys p's AST; do not call any methods of p after it returns.

func (*Package) RenderParts Uses

func (p *Package) RenderParts(ctx context.Context, innerPath string, sourceInfo *source.Info, modInfo *ModuleInfo) (_ *dochtml.Parts, err error)

RenderParts renders the documentation for the package in parts. Rendering destroys p's AST; do not call any methods of p after it returns.

type Renderer Uses

type Renderer struct {

A Renderer renders documentation for a Package.


codecPackage codec implements the general-purpose part of an encoder for Go values.
dochtmlPackage dochtml renders Go package documentation into HTML.
dochtml/internal/renderPackage render formats Go documentation as HTML.
internal/docPackage doc extracts source code documentation from a Go AST.

Package godoc imports 20 packages (graph) and is imported by 4 packages. Updated 2021-01-17. Refresh now. Tools for package owners.