codoc

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: MIT Imports: 2 Imported by: 2

README

codoc

GoDoc

Extract Go package documentation to be used at runtime.

Usage

To generate a documentation file for a Go package, run the following command:

go run github.com/noonien/codoc/cmd/codoc@latest -pkg main -out example_doc.go ./example

This will generate an example_doc.go file that registers the package documentation with the codoc package. Assuming the example_doc.go file is imported somewhere by your program, the documentation can be accessed like so:

package main

import (
    "github.com/noonien/codoc"

    // make sure example_doc.go is part of, or imported by your program
)

func main() {
    pkg := codoc.Package("main")      // Get documentation for the main package
    fn := codoc.Function("main.Foo")  // Get documentation for the function Foo in the main package
    st := codoc.Struct("main.Bar")    // Get documentation for the struct Bar in the main package

    // Example usage
    fmt.Println(pkg)
    fmt.Println(fn)
    fmt.Println(st)
}

License

codoc is released under the MIT License. See the LICENSE file for more details.

Documentation

Overview

Package codoc provides functionality for storing and retrieving code documentation. It defines data structures for representing code elements like packages, functions, and structs, and provides an API for registering and retrieving documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(pkg Package)

Register adds a package and all its components to the global registry. It uses the package's ID as a prefix for registering functions and structs.

Types

type Field

type Field struct {
	Name    string // Field name
	Doc     string // Field documentation string
	Comment string // Inline comment for the field
}

Field represents a field in a struct with its documentation.

type Function

type Function struct {
	Name    string   // Function name
	Doc     string   // Function documentation string
	Args    []string // List of argument names
	Results []string // List of result names
}

Function represents a Go function with its documentation. It includes the function's name, documentation, and parameter information.

func GetFunction

func GetFunction(id string) *Function

GetFunction retrieves a function from the registry by its ID. The ID can be either a direct function ID or a struct method ID (pkg.struct.method). Returns nil if the function is not found.

type Package

type Package struct {
	ID        string              // Unique identifier for the package
	Name      string              // Package name
	Doc       string              // Package documentation string
	Functions map[string]Function // Map of functions in the package
	Structs   map[string]Struct   // Map of structs in the package
}

Package represents a Go package with its documentation. It contains information about the package itself, as well as maps of the functions and structs defined within it.

func GetPackage

func GetPackage(id string) *Package

GetPackage retrieves a package from the registry by its ID. Returns nil if the package is not found.

type Struct

type Struct struct {
	Name    string              // Struct name
	Doc     string              // Struct documentation string
	Fields  map[string]Field    // Map of fields in the struct
	Methods map[string]Function // Map of methods associated with the struct
}

Struct represents a Go struct with its documentation. It includes the struct's name, documentation, fields, and methods.

func GetStruct

func GetStruct(id string) *Struct

GetStruct retrieves a struct from the registry by its ID. Returns nil if the struct is not found.

Directories

Path Synopsis
cmd
codoc command
Package main provides a command-line tool for generating code documentation.
Package main provides a command-line tool for generating code documentation.
Package codocgen provides tools for generating code documentation from Go source code.
Package codocgen provides tools for generating code documentation from Go source code.

Jump to

Keyboard shortcuts

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