gofasta g repo-method
The repository-layer twin of g method. Identical semantics — patches an existing interface and impl, AST-based, idempotent — with repository-specific default paths:
- Interface:
app/repositories/interfaces/<snake>_repository.go - Impl:
app/repositories/<snake>.repository.go - Naming:
<Resource>RepositoryInterface+<lowerResource>Repository
Use this for data-access methods (FK lookups, custom queries, batch operations). Use g method for business-logic methods on the service layer.
Usage
gofasta g repo-method <Resource> <Method> [param:type ...] [flags]Flags
| Flag | Default | Description |
|---|---|---|
--dry-run | false | Preview the patches without writing. Honors --json for a structured plan. |
Examples
Add a FindByCustomer query:
gofasta g repo-method Order FindByCustomer customerID:uuidResult — app/repositories/interfaces/order_repository.go:
type OrderRepositoryInterface interface {
// ... existing methods preserved ...
FindByCustomer(ctx context.Context, customerID uuid.UUID) error
}And app/repositories/order.repository.go:
// FindByCustomer is a generated stub. Replace with the real implementation.
func (s *orderRepository) FindByCustomer(ctx context.Context, customerID uuid.UUID) error {
return fmt.Errorf("OrderRepositoryInterface.FindByCustomer: not implemented")
}Add a method with no params:
gofasta g repo-method Order ArchiveAllPreview without writing:
gofasta g repo-method Order BulkInsert --dry-run --jsonArgument convention
Same as g method — every generated method takes ctx context.Context first, returns error last, with user-supplied args between.
Error codes
| Code | When |
|---|---|
RESOURCE_NOT_FOUND | The interface or impl file is missing. Run gofasta g scaffold <Resource> first. |
METHOD_ALREADY_EXISTS | The interface already declares a method by that name. |
AST_PARSE_FAILED | One of the target files has a syntax error. |
Last updated on