template

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
	},
}
View Source
var CmdGenerate = &cobra.Command{
	Use: "generate",
	RunE: func(cmd *cobra.Command, args []string) error {
		return nil
	},
}

Functions

This section is empty.

Types

type CommentTag

type CommentTag struct {
	Name  string
	Value string
	Line  int
}

type GoComment

type GoComment struct {
	Text string
	Kind string
	Line int
}

func (GoComment) HasTag

func (c GoComment) HasTag(name string) bool

HasTag reports whether the comment contains a tag like "@name" or "@name: value".

func (GoComment) TagValue

func (c GoComment) TagValue(name string) (string, bool)

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

func (f GoField) CommentTagValue(name string) (string, bool)

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

func (f GoField) HasCommentTag(name string) bool

HasCommentTag reports whether the field's doc or inline comments include a tag. Example:

// @validate: required
Name string

func (GoField) TagName

func (f GoField) TagName(name string) (string, bool)

TagName returns the first segment of a struct tag value. Example: `json:"name,omitempty"` -> TagName("json") == "name".

func (GoField) TagValue

func (f GoField) TagValue(name string) (string, bool)

TagValue returns the raw struct tag value for name (e.g. "json", "db").

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

func (f GoFunc) CommentTagValue(name string) (string, bool)

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

func (f GoFunc) HasCommentTag(name string) bool

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

func ParseGoPath(root string) ([]GoPackage, error)

ParseGoPath collects package metadata for a module path or a single Go file. Example: pkgs, err := ParseGoPath(".")

func (GoPackage) FieldsOf

func (p GoPackage) FieldsOf(typeName string) []GoField

FieldsOf returns the fields for a named type, if present. Example: fields := pkg.FieldsOf("User")

func (GoPackage) FindType

func (p GoPackage) FindType(name string) (GoType, bool)

FindType looks up a type by name in the package.

func (GoPackage) FuncsByReceiver

func (p GoPackage) FuncsByReceiver() map[string][]GoFunc

FuncsByReceiver groups methods by their receiver type. Example: receivers := pkg.FuncsByReceiver(); receivers["*User"]

func (GoPackage) MethodsOf

func (p GoPackage) MethodsOf(typeName string) []GoFunc

MethodsOf returns all methods whose receiver matches the given type name. Example: methods := pkg.MethodsOf("User")

func (GoPackage) TypesByName

func (p GoPackage) TypesByName() map[string]GoType

TypesByName returns a map keyed by type name for quick lookups.

type GoParam

type GoParam struct {
	Name string
	Type string
}

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

func (t GoType) CommentTagValue(name string) (string, bool)

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

func (t GoType) HasCommentTag(name string) bool

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

func (t GoType) MethodsFrom(funcs []GoFunc) []GoFunc

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"
)

Jump to

Keyboard shortcuts

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