gosource

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package gosource reads doc comments out of Go source so reflected schemas can carry prose.

Reflection sees structure and nothing else: Go's runtime does not retain doc comments, so a purely reflective OpenAPI schema is structurally complete and entirely undocumented. The alternative the ecosystem settled on — encoding documentation into struct tags or magic comments — puts a second, unchecked language in the source. This package takes the third option: the doc comment stays an ordinary doc comment, and the generator reads it from the source it is already sitting in.

Only the generator needs this. A shipped binary serves a contract that was compiled with the comments already folded in, so nothing here runs at runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Docs

type Docs struct {
	// contains filtered or unexported fields
}

Docs is a lookup from Go type and field to doc comment.

It implements tapesoapi.TypeDocs, which is the only thing the reflector needs from it.

func Load

func Load(dir string, opts ...Option) (*Docs, error)

Load scans a module rooted at dir and indexes its doc comments.

The module path comes from go.mod, so the keys match the PkgPath reflection reports — which is what lets a reflected type find its own comments without the caller maintaining a mapping.

func (*Docs) FieldDoc

func (d *Docs) FieldDoc(pkgPath, typeName, fieldName string) string

FieldDoc implements tapesoapi.TypeDocs.

func (*Docs) Len

func (d *Docs) Len() int

Len reports how many types were indexed, for a generator that wants to say so.

func (*Docs) TypeDoc

func (d *Docs) TypeDoc(pkgPath, typeName string) string

TypeDoc implements tapesoapi.TypeDocs.

type Option

type Option func(*options)

Option configures a Load.

func SkipDirs

func SkipDirs(names ...string) Option

SkipDirs omits directories, by base name, from the scan.

Jump to

Keyboard shortcuts

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