godoc

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	TypeFunction = "function"
	TypeType     = "type"
	TypeMethod   = "method"
	TypeVar      = "var"
	TypeConst    = "const"
)

Symbol types for Doc

Variables

This section is empty.

Functions

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 LoadWithFallback

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

LoadWithFallback attempts to resolve an import path and return documentation. It attempts to find parent packages if the exact match fails.

func (*Doc) Clone added in v0.34.0

func (d *Doc) Clone() *Doc

Clone creates a deep copy of Doc for concurrency safety.

func (*Doc) RenderJSON added in v0.26.0

func (d *Doc) RenderJSON() (string, error)

RenderJSON marshals the Doc into formatted JSON.

func (*Doc) RenderMarkdown added in v0.26.0

func (d *Doc) RenderMarkdown() string

RenderMarkdown converts a Doc to Markdown.

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