golazy.dev golazy.dev / lazydoc Index | Files

package lazydoc

import "golazy.dev/lazydoc"

Package lazydoc extracts, stores, loads, and searches Go package documentation as a small JSON-friendly index.

LoadDir reads a module directory, gets its module path from go.mod, walks its package directories, and uses the standard go/parser and go/doc packages to collect package comments, declarations, constants, variables, functions, types, and methods. LoadPackagesFromDir does the same package walk when the caller already knows the module path. Both functions ignore test packages, vendor, testdata, node_modules, .git, and hidden directories.

The model keeps source metadata beside each package or symbol. Source is the source file path relative to the module root plus the original line number. It intentionally does not store an absolute path, so generated indexes can be embedded, committed, or served from another machine. apps/golazy.dev uses this metadata to turn package headings and symbol headings into repository links on the public package documentation pages.

The data types in this package are deliberately plain structs with JSON tags. A build or documentation command can call LoadDir and marshal the resulting Index or Version. A web application can later use LoadJSON or LoadJSONBytes to load that index without reparsing source code at request time. Index also provides small lookup helpers for version, package, symbol, and search pages.

The public GoLazy site uses lazydoc from apps/golazy.dev/cmd/packagedocs to generate data/package_docs/*.json, then loads those files through the webcontent service for the /packages routes. Most GoLazy applications do not need lazydoc at runtime; use it directly when building a package reference, search index, local documentation browser, or another module-level docs surface.

Types

type Example

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

type Func

type Func struct {
	Name		string		`json:"name"`
	Doc		string		`json:"doc"`
	Decl		string		`json:"decl"`
	Source		*Source		`json:"source,omitempty"`
	Examples	[]Example	`json:"examples,omitempty"`
}

type Index

type Index struct {
	Versions []Version `json:"versions"`
}
func LoadDir
func LoadDir(dir, version string) (*Index, error)
func LoadJSON
func LoadJSON(root fs.FS, file string) (*Index, error)
func LoadJSONBytes
func LoadJSONBytes(data []byte) (*Index, error)
func (i *Index) Latest
func (i *Index) Latest() (*Version, bool)
func (i *Index) Search
func (i *Index) Search(version, query string) []SearchResult
func (i *Index) Version
func (i *Index) Version(value string) (*Version, bool)

type Package

type Package struct {
	ImportPath	string		`json:"import_path"`
	Name		string		`json:"name"`
	Synopsis	string		`json:"synopsis"`
	Doc		string		`json:"doc"`
	Source		*Source		`json:"source,omitempty"`
	Constants	[]Value		`json:"constants,omitempty"`
	Variables	[]Value		`json:"variables,omitempty"`
	Functions	[]Func		`json:"functions,omitempty"`
	Types		[]Type		`json:"types,omitempty"`
	Examples	[]Example	`json:"examples,omitempty"`
}
func LoadPackagesFromDir
func LoadPackagesFromDir(dir, modulePath string) ([]Package, error)
func (p Package) Slug
func (p Package) Slug() string
func (p Package) Symbol
func (p Package) Symbol(name string) (kind string, title string, doc string, decl string, ok bool)

type Type

type Type struct {
	Name		string		`json:"name"`
	Doc		string		`json:"doc"`
	Decl		string		`json:"decl"`
	Source		*Source		`json:"source,omitempty"`
	Constants	[]Value		`json:"constants,omitempty"`
	Variables	[]Value		`json:"variables,omitempty"`
	Funcs		[]Func		`json:"functions,omitempty"`
	Methods		[]Func		`json:"methods,omitempty"`
	Examples	[]Example	`json:"examples,omitempty"`
}

type Value

type Value struct {
	Names	[]string	`json:"names"`
	Doc	string		`json:"doc"`
	Decl	string		`json:"decl"`
	Source	*Source		`json:"source,omitempty"`
}