usecase-go

Implements Go application use cases as types.Handler structs with UnitOfWork transactions and fx wiring.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill usecase-go-gabriellst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: usecase-go
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/usecase/go
Command: npx skills add https://github.com/gabriellst/codm --skill usecase-go-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Go application-layer use cases consistently is hard: transactions, domain event persistence, validation, and dependency injection are easy to get wrong, leading to partial writes, lost events, and unmappable errors. This Skill codifies the exact pattern for implementing use cases that satisfy the types.Handler[I,O] contract inside a DDD/CQRS Go backend. ## Core Features & Use Cases - Handler Implementation Pattern: Guides creation of structs implementing Name() and Execute(ctx, input) with validate-tagged Input/Output structs. - Transactional Integrity: Enforces the UnitOfWork pattern where all repository saves and domain event persistence (outbox) run inside one transaction, while external I/O runs after commit. - fx Dependency Wiring: Shows constructor injection and fx.Provide registration in module.go, with handlers consumed as concrete pointer types. - Use Case: When adding a "complete transcoding job" command, follow the Skill to define validated input, load the entity in a transaction, apply behavior, save the entity plus its domain events atomically, and register the handler with fx. ## Quick Start Ask the agent to create a new Go use case for a given bounded context following the usecase-go skill, providing the context name, entity, and repository.

Frequently Asked Questions about usecase-go

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a use case handler in Go with fx dependency injection?

Define a struct with unexported dependency fields, a NewXHandler constructor, and Name() plus Execute(ctx, input) methods implementing types.Handler[I,O]. Register it with fx.Provide(usecases.NewXHandler) in module.go; controllers consume it as a concrete pointer type without fx.As.

How to run repository saves inside a transaction in Go?

Wrap all DB mutations in uow.Execute(ctx, func(txCtx context.Context) error { ... }) and pass txCtx to every repository call. The UnitOfWork commits when the callback returns nil and rolls back on any returned error.

When should domain events be persisted in a Go use case?

Persist domain events inside the same UnitOfWork transaction as the entity save by looping over entity.PullDomainEvents() and calling domainEventRepo.Save(txCtx, e). Never call a mediator directly; the outbox dispatcher delivers events asynchronously after commit.

Can I call external services inside a UnitOfWork transaction?

No. External I/O such as service calls or HTTP requests must run after uow.Execute returns. Running them inside the closure holds the database connection open during the call and increases the risk of partial state on failure.

Why should Go use case inputs have validate tags if controllers already validate?

Go use cases are also invoked from non-HTTP paths like webhook choreography, integration-event handlers, and sync workers where no controller request struct exists. The validate tags on the Input struct are the only format gate on those paths, so they are required.

When should I not use the use case pattern in Go?

Do not use it for read queries serving UI or internal coordination, which follow the query skill's ctx-local read pattern, or for reacting to events, which belongs to the event handler skill. It is meant for state-changing commands needing transactional orchestration.