godoc

package
v0.20.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package godoc implements the core logic for retrieving and parsing Go documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDocumentation

func GetDocumentation(ctx context.Context, pkgPath, symbolName string) (string, error)

GetDocumentation retrieves the documentation for a package or symbol as Markdown.

func GetDocumentationWithFallback

func GetDocumentationWithFallback(ctx context.Context, pkgPath string) (string, error)

GetDocumentationWithFallback attempts to retrieve documentation for a package. If the specific package documentation is not found, it attempts to find documentation for parent paths (module roots) and returns it with a hint.

func ListSubPackages

func ListSubPackages(ctx context.Context, pkgDir string) []string

ListSubPackages finds sub-packages within a directory using go list.

func Render

func Render(doc *Doc) string

Render converts a Doc to Markdown.

Types

type Doc

type Doc struct {
	Package      string    `json:"package"`
	ImportPath   string    `json:"importPath"`
	ResolvedPath string    `json:"resolvedPath,omitempty"`
	SymbolName   string    `json:"symbolName,omitempty"`
	Type         string    `json:"type,omitempty"` // "function", "type", "var", "const"
	Definition   string    `json:"definition,omitempty"`
	Description  string    `json:"description"`
	Examples     []Example `json:"examples,omitempty"`
	SubPackages  []string  `json:"subPackages,omitempty"`
	PkgGoDevURL  string    `json:"pkgGoDevURL"`

	// Lists of symbols (signatures or summaries)
	Funcs  []string `json:"funcs,omitempty"`
	Types  []string `json:"types,omitempty"`
	Vars   []string `json:"vars,omitempty"`
	Consts []string `json:"consts,omitempty"`

	// Extra fields for Describe superset
	SourcePath string   `json:"sourcePath,omitempty"`
	Line       int      `json:"line,omitempty"`
	References []string `json:"references,omitempty"`
}

Doc represents the parsed documentation.

func Extract

func Extract(pkg *packages.Package, symbolName string) (*Doc, error)

Extract returns documentation from an already loaded packages.Package. It is efficient (no I/O) as it reuses the existing AST and Type information. Use this when you have a *packages.Package available.

func Load

func Load(ctx context.Context, pkgPath, symbolName string) (*Doc, error)

Load resolves an import path and returns documentation. It performs disk I/O ("go list") and parsing. Use this when starting from a string path.

func LoadWithFallback

func LoadWithFallback(ctx context.Context, pkgPath, symbolName string) (*Doc, error)

LoadWithFallback is like Load but attempts to find parent packages if the exact match fails.

type Example

type Example struct {
	Name   string `json:"name"`
	Code   string `json:"code"`
	Output string `json:"output,omitempty"`
}

Example represents a code example extracted from documentation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL