gen

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectRepoCalls

func CollectRepoCalls(src string) map[string]struct{}

CollectRepoCalls returns the set of Repository method names called in src.

func CollectServiceCalls

func CollectServiceCalls(src string) map[string]struct{}

CollectServiceCalls returns the set of Service method names called in src.

func DetectModulePath

func DetectModulePath(root string) (string, error)

DetectModulePath reads the module directive from go.mod in root.

func InferPortPrefix

func InferPortPrefix(pkg *ast.Package) (string, bool)

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

func MethodSigs(pkg *ast.Package, typeName string) map[string]string

MethodSigs parses pkg and returns a map of methodName → signature string for all exported methods on *typeName.

func PackageName

func PackageName(path string) (string, error)

PackageName reads the package name from a Go source file.

func ParsePackage

func ParsePackage(dir string) (*ast.Package, error)

ParsePackage parses all non-test .go files in dir (excluding ports.go and adapters).

func PortPrefix

func PortPrefix(dirBase string) string

PortPrefix returns the PascalCase prefix for interface names based on the directory name. "orders" → "Orders", "api_keys" → "ApiKeys".

func SortSet

func SortSet(m map[string]struct{}) []string

SortSet returns the keys of a set map sorted alphabetically.

func Union

func Union(a, b map[string]struct{}) map[string]struct{}

Union merges b into a and returns a.

Types

This section is empty.

Jump to

Keyboard shortcuts

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