Documentation
¶
Index ¶
- type Annotation
- type Collector
- func (c *Collector) Entries() []Entry
- func (c *Collector) EntriesWith(annotation string) []Entry
- func (c *Collector) EntriesWithArgType(annotationName string, argumentType string) []Entry
- func (c *Collector) EntriesWithPrefix(prefix string) []Entry
- func (c *Collector) EntriesWithResultType(annotation string, result string) []Entry
- type Entry
- type EntryField
- type EntryFunc
- type EntryFuncType
- type EntryHeader
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotation ¶
type Annotation struct {
Name string // Name of the annotation, without the "@"
Value string // Text between the parentheses, as written in the source
Map map[string]interface{} // Parsed key=value pairs
}
Annotation is a single `// @Name(key=value, ...)` line found in a doc comment.
func NewAnnotation ¶
func NewAnnotation(name string, value string) Annotation
NewAnnotation builds an annotation from its name and the text between its parentheses. Values are split on top-level commas: commas inside double quotes or brackets belong to the value, and only the first "=" separates the key. Unquoted values become int, float64 or bool (true/false) when they parse as such; quoted values are always strings.
func (*Annotation) Decode ¶
func (m *Annotation) Decode(a interface{}) error
Decode copies the parsed values into a, matching keys with `attr` tags.
func (*Annotation) RawValue ¶
func (m *Annotation) RawValue() string
RawValue returns the text between the parentheses, as written in the source.
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
func Collect ¶
Collect loads every package under the base path (as `go list ./...` sees it from there: hidden, underscore, testdata and vendor directories are skipped) plus the packages they import, and returns the annotated declarations. Standard library packages are never scanned; WithPackages restricts the scan to the given import paths and the packages below them.
func (*Collector) EntriesWith ¶
func (*Collector) EntriesWithArgType ¶
func (*Collector) EntriesWithPrefix ¶
type Entry ¶
type Entry struct {
Header EntryHeader // Metadata for the entry
Comments []string
Module string // Name of the module where the entry is located
File string // Name of the file where the entry is located
Path string // Path to the file where the entry is located
Package string // Name of the package where the entry is located
Func EntryFunc // Details about the function in the entry
Struct string // Name of the struct in the entry
Fields []EntryField // Fields of the struct, for a struct entry
Annotations []Annotation // Annotations for the entry
// Imports maps the name the file uses for each import (its alias, or the
// imported package's name) to the import path. Blank and dot imports are
// left out. Entries of the same file share the map.
Imports map[string]string
}
Entry represents a single entry parsed from the *ast.File.
type EntryField ¶
type EntryField struct {
Name string // Name of the field, "" for an embedded field
Type string // Type of the field, as written
Tag string // Tag of the field, without the backquotes
}
EntryField is a field of a struct entry.
type EntryFunc ¶
type EntryFunc struct {
Name string // Name of the function
Parameters []EntryFuncType // Parameters of the function
Results []EntryFuncType // Results of the function
}
EntryFunc represents a function and its details.
type EntryFuncType ¶
type EntryFuncType struct {
Name string // Name of the parameter/result
Type string // Type of the parameter/result
}
EntryFuncType represents a parameter or a result type of a function.
type EntryHeader ¶
type EntryHeader struct {
Title string // Title of the entry
Description string // Description of the entry
}
EntryHeader represents the metadata for an entry.
type Option ¶
func WithFilters ¶
WithFilters keeps only the annotations whose name starts with one of the filters: "Rest" keeps @Rest, @RestRouter and @RestResponse.
func WithPackageDocs ¶ added in v1.7.0
func WithPackageDocs() Option
WithPackageDocs also collects the annotations of package doc comments, each file's as an entry whose IsPackage is true. Without it, only declarations are collected.
func WithPackages ¶
WithPackages restricts the scan to the given import paths and the packages below them, both under the base path and among their imports.