Documentation
¶
Overview ¶
Package gen implements the core logic for the portsmith gen command: AST-based method signature extraction and regex-based call collection. The generator reads existing handler/service/repository files and produces a minimal ports.go with only the interface methods that are actually used.
Index ¶
- func CollectRepoCalls(src string) map[string]struct{}
- func CollectServiceCalls(src string) map[string]struct{}
- func DetectModulePath(root string) (string, error)
- func InferPortPrefix(pkg *ast.Package) (string, bool)
- func MethodSigs(pkg *ast.Package, typeName string) map[string]string
- func PackageName(path string) (string, error)
- func ParsePackage(dir string) (*ast.Package, error)
- func PortPrefix(dirBase string) string
- func SortSet(m map[string]struct{}) []string
- func Union(a, b map[string]struct{}) map[string]struct{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectRepoCalls ¶
CollectRepoCalls returns the set of Repository method names called in src.
func CollectServiceCalls ¶
CollectServiceCalls returns the set of Service method names called in src.
func DetectModulePath ¶
DetectModulePath reads the module directive from go.mod in root.
func InferPortPrefix ¶
InferPortPrefix derives the interface name prefix from Handler and Service struct fields when dependency types are named like WebPushRepository / WebPushService.
This fixes directory names such as "webpush" where PortPrefix yields "Webpush" while the codebase uses the idiomatic "WebPush".
func MethodSigs ¶
MethodSigs parses pkg and returns a map of methodName → signature string for all exported methods on *typeName.
func PackageName ¶
PackageName reads the package name from a Go source file.
func ParsePackage ¶
ParsePackage parses all non-test .go files in dir (excluding ports.go and adapters).
func PortPrefix ¶
PortPrefix returns the PascalCase prefix for interface names based on the directory name. "orders" → "Orders", "api_keys" → "ApiKeys".
Types ¶
This section is empty.