pkgsite: Index | Files | Directories

package godoc

import ""

Package godoc is for rendering Go documentation.


Package Files

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


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 Parse Uses

func Parse(docHTML safehtml.HTML, section SectionType) (_ safehtml.HTML, err error)

Parse return the section of docHTML specified by section. It is expected that docHTML was generated using the template in internal/fetch/dochtml.

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.

type SectionType Uses

type SectionType uint32

SectionType is a section of the docHTML.

const (
    // SidenavSection is the section of the docHTML starting at
    // dochtml.IdentifierSidenav and ending at the last </nav> tag in the
    // docHTML. This is inclusive of SideNavMobile.
    SidenavSection SectionType = iota
    // SidenavMobileSection is the section of the docHTML starting at
    // dochtml.IdentifierMobileNavStart and ending at the last </nav> tag in the
    // docHTML.
    // BodySection is the section of the docHTML starting at
    // dochtml.IdentifierBody and ending at the last </div> tag in the
    // docHTML.


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 23 packages (graph) and is imported by 2 packages. Updated 2020-10-28. Refresh now. Tools for package owners.