goca interfaces
Generate interface contracts for Test-Driven Development.
Syntax
bash
goca interfaces <EntityName> [flags]Description
Generates only the interface contracts without implementations, perfect for TDD workflows where you define contracts first.
Flags
--usecase
Generate use case interfaces.
bash
goca interfaces Product --usecase--repository
Generate repository interfaces.
bash
goca interfaces User --repository--all
Generate all interfaces.
bash
goca interfaces Order --allExamples
Use Case Interfaces
bash
goca interfaces Product --usecaseGenerates: internal/usecase/product_interfaces.go
go
package usecase
import "context"
type ProductService interface {
CreateProduct(ctx context.Context, input CreateProductInput) (*ProductResponse, error)
GetProduct(ctx context.Context, id uint) (*ProductResponse, error)
UpdateProduct(ctx context.Context, id uint, input UpdateProductInput) error
DeleteProduct(ctx context.Context, id uint) error
ListProducts(ctx context.Context) ([]*ProductResponse, error)
}Repository Interfaces
bash
goca interfaces User --repositoryGenerates: internal/repository/user_interfaces.go
go
package repository
import (
"context"
"myproject/internal/domain"
)
type UserRepository interface {
Save(ctx context.Context, user *domain.User) error
FindByID(ctx context.Context, id uint) (*domain.User, error)
FindAll(ctx context.Context) ([]*domain.User, error)
Update(ctx context.Context, user *domain.User) error
Delete(ctx context.Context, id uint) error
}All Interfaces
bash
goca interfaces Order --allTDD Workflow
Generate Interfaces:
bashgoca interfaces Payment --allWrite Tests:
gofunc TestPaymentService_CreatePayment(t *testing.T) { mockRepo := &MockPaymentRepository{} service := NewPaymentService(mockRepo) // ... test implementation }Implement: Implement the actual service and repository.
See Also
goca usecase- Generate full use casesgoca repository- Generate repositories