Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Cmd = &cobra.Command{ Use: "template", FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, RunE: func(cmd *cobra.Command, args []string) error { err := cmd.ParseFlags(args) if err != nil { return err } pkgs, err := ParseGoPath(rkit.Must(filepath.Abs("."))) if err != nil { return err } cmd.Println("packages:") for _, pkg := range pkgs { cmd.Println(pkg.Name) cmd.Println("files:", len(pkg.Files)) cmd.Println("types:", len(pkg.Types)) for _, f := range pkg.Functions { cmd.Println("\t", f.Name, f.Receiver, f.ReceiverType, f.Params, f.Results) } cmd.Println("comments", len(pkg.Comments)) } return nil }, }
Functions ¶
This section is empty.
Types ¶
type CommentTag ¶
type GoComment ¶
func (GoComment) HasTag ¶
HasTag reports whether the comment contains a tag like "@name" or "@name: value".
func (GoComment) TagValue ¶
TagValue returns the value for a tag in the comment. Example: "// @owner: platform" -> TagValue("owner") == "platform".
func (GoComment) Tags ¶
func (c GoComment) Tags() []CommentTag
type GoField ¶
type GoField struct {
Name string
Type string
Tag string
Embedded bool
Exported bool
Doc string
Comments []GoComment
}
func (GoField) CommentTagValue ¶
CommentTagValue returns the value for a tag from the field's doc or inline comments.
func (GoField) CommentTags ¶
func (f GoField) CommentTags() []CommentTag
func (GoField) HasCommentTag ¶
HasCommentTag reports whether the field's doc or inline comments include a tag. Example:
// @validate: required Name string
type GoFunc ¶
type GoFunc struct {
Name string
Exported bool
File string
Doc string
Comments []GoComment
Receiver string
ReceiverType string
Params []GoParam
Results []GoParam
}
func (GoFunc) CommentTagValue ¶
CommentTagValue returns the value for a tag from the function's doc or inline comments.
func (GoFunc) CommentTags ¶
func (f GoFunc) CommentTags() []CommentTag
func (GoFunc) HasCommentTag ¶
HasCommentTag reports whether the function's doc or inline comments include a tag. Example:
// CreateUser creates a new user.
// @role: admin
func CreateUser(...) {}
type GoPackage ¶
type GoPackage struct {
Name string
Dir string
Files []string
Types []GoType
Functions []GoFunc
Comments []GoComment
}
func ParseGoPath ¶
ParseGoPath collects package metadata for a module path or a single Go file. Example: pkgs, err := ParseGoPath(".")
func (GoPackage) FieldsOf ¶
FieldsOf returns the fields for a named type, if present. Example: fields := pkg.FieldsOf("User")
func (GoPackage) FuncsByReceiver ¶
FuncsByReceiver groups methods by their receiver type. Example: receivers := pkg.FuncsByReceiver(); receivers["*User"]
func (GoPackage) MethodsOf ¶
MethodsOf returns all methods whose receiver matches the given type name. Example: methods := pkg.MethodsOf("User")
func (GoPackage) TypesByName ¶
TypesByName returns a map keyed by type name for quick lookups.
type GoType ¶
type GoType struct {
Name string
Kind GoTypeKind
Exported bool
File string
Doc string
Comments []GoComment
Underlying string
Fields []GoField
Methods []GoFunc
}
func (GoType) CommentTagValue ¶
CommentTagValue returns the value for a tag from the type's doc or inline comments.
func (GoType) CommentTags ¶
func (t GoType) CommentTags() []CommentTag
func (GoType) HasCommentTag ¶
HasCommentTag reports whether the type's doc or inline comments include a tag. Example:
// User is a domain model.
// @domain: identity
type User struct {}
func (GoType) MethodsFrom ¶
MethodsFrom filters package-level functions to those with receivers matching this type. Example:
for _, m := range myType.MethodsFrom(pkg.Functions) { fmt.Println(m.Name) }
type GoTypeKind ¶
type GoTypeKind string
const ( GoTypeStruct GoTypeKind = "struct" GoTypeInterface GoTypeKind = "interface" GoTypeAlias GoTypeKind = "alias" GoTypeOther GoTypeKind = "other" )