Token导航 LogoToken导航TokenDH.com
研究检索只读github未标认证来源可访问许可证需确认审计通过

go-create-usecase去创建用例

Agent Skill

go-create-usecase 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

275

周安装

11

GitHub Stars

公开资料未说明

下载量

89
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:go-create-usecase(去创建用例)
来源仓库:https://github.com/cristiano-pacheco/ai-rules
仓库路径:skills/go-create-usecase
安装命令:
npx skills add https://github.com/cristiano-pacheco/ai-rules --skill go-create-usecase
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/cristiano-pacheco/ai-rules --skill go-create-usecase

简介

用于查找、检索和筛选相关信息。

  • 适合在关键词搜索或任务场景下快速定位候选结果。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装,需确认权限范围。
  • 使用前建议核验是否会触发联网或文件读写操作。
  • go-create-usecase 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Go Create UseCase

Generate a use case that depends on ports (interfaces), not concrete implementations.

Create the file

Create one file per operation in: internal/modules/<module>/usecase/<operation>_usecase.go

Use:

  • package: usecase
  • struct name: <Operation>UseCase
  • method name: Execute

Naming (CRITICAL)

Apply consistent naming for every use case.

Rules:

  • file: <operation>_usecase.go
  • input DTO: <Operation>Input
  • output DTO: <Operation>Output
  • use case struct: <Operation>UseCase
  • constructor: New<Operation>UseCase

Example (contact_create):

  • file: contact_create_usecase.go
  • input: ContactCreateInput
  • output: ContactCreateOutput
  • struct: ContactCreateUseCase
  • constructor: NewContactCreateUseCase

Example (contact_list, no real input):

  • file: contact_list_usecase.go
  • input: ContactListInput (empty struct)
  • output: ContactListOutput
  • struct: ContactListUseCase
  • constructor: NewContactListUseCase

Follow the structure (CRITICAL)

Implement this order in the file:

  1. Input struct (ALWAYS present; can be empty)
  2. Output struct (ALWAYS present; can be empty)
  3. Use case struct with dependencies
  4. Constructor New<Operation>UseCase
  5. Public Execute method (contains all business logic)
  6. Input and Output must NOT CONTAIN json tags, only validation tags when needed for input.

Current architecture rule

Use cases contain business logic only.

Do NOT include in usecases:

  • logger dependencies
  • metrics dependencies
  • tracing code
  • private execute method wrappers

Observability and error translation are handled by ucdecorator in Fx wiring.

Use this template

package usecase

import (
	"context"

	"github.com/cristiano-pacheco/bricks/pkg/validator"
	"github.com/cristiano-pacheco/catzi/internal/modules/<module>/ports"
)

type <Operation>Input struct {
	Field string `validate:"required,max=255"`
}

type <Operation>Output struct {
	Result string
}

type <Operation>UseCase struct {
	repo      ports.<Entity>Repository
	validator validator.Validator // include only if needed
}

func New<Operation>UseCase(
	repo ports.<Entity>Repository,
	validator validator.Validator,
) *<Operation>UseCase {
	return &<Operation>UseCase{
		repo:      repo,
		validator: validator,
	}
}

func (uc *<Operation>UseCase) Execute(ctx context.Context, input <Operation>Input) (<Operation>Output, error) {
	if err := uc.validator.Validate(input); err != nil {
		return <Operation>Output{}, err
	}

	// Add business orchestration here
	// - read/write via repositories
	// - call domain services
	// - map model to output DTO

	return <Operation>Output{}, nil
}

Apply variants

No-input use case

When no parameters are needed, still define an empty input:

type ContactListInput struct{}

And keep the same contract:

func (uc *ContactListUseCase) Execute(ctx context.Context, input ContactListInput) (ContactListOutput, error)

No-output use case

When no result payload is needed, define an empty output:

type ContactDeleteOutput struct{}

And return it:

return ContactDeleteOutput{}, nil

No-validation use case

When validation is not required, remove validator.Validator from dependencies and skip validation.

Multi-dependency orchestration

Inject multiple ports as interfaces (repositories, caches, services) in the use case struct and constructor.

Apply common patterns

Check existing record before create

import brickserrors "github.com/cristiano-pacheco/pkg/errs"

record, err := uc.repo.FindByX(ctx, input.Field)
if err != nil && !errors.Is(err, brickserrors.ErrRecordNotFound) {
	return output, err
}
if record.ID != 0 {
	return output, brickserrors.ErrAlreadyExists
}

Convert enum from input

enumVal, err := enum.NewTypeEnum(input.Type)
if err != nil {
	return output, err
}
model.Type = enumVal.String()

Map list response

items, err := uc.repo.FindAll(ctx)
if err != nil {
	return output, err
}

output.Items = make([]ItemOutput, len(items))
for i, item := range items {
	output.Items[i] = ItemOutput{ID: item.ID, Name: item.Name}
}

Wire with Fx

Register raw usecases and decorate them via ucdecorator.

Minimal provider example

fx.Provide(
	usecase.New<Operation>UseCase,
)

Decorator wiring pattern (recommended)

Use a consolidated provider (fx.In + fx.Out) and wrap usecases with:

ucdecorator.Wrap(factory, rawUseCase)

Wrap infers:

  • usecase name (e.g. CategoryCreateUseCase.Execute)
  • metric name (e.g. category_create)

No need to pass metric/usecase name strings manually.

Full module wiring pattern (single-file, fx.In + fx.Out)

Use this when the module has multiple usecases and you want less boilerplate in fx.go.

type decorateIn struct {
	fx.In

	Factory *ucdecorator.Factory
	Create  *usecase.<Entity>CreateUseCase
	List    *usecase.<Entity>ListUseCase
}

type decorateOut struct {
	fx.Out

	Create ucdecorator.UseCase[usecase.<Entity>CreateInput, usecase.<Entity>CreateOutput]
	List   ucdecorator.UseCase[usecase.<Entity>ListInput, usecase.<Entity>ListOutput]
}

func provideDecoratedUseCases(in decorateIn) decorateOut {
	return decorateOut{
		Create: ucdecorator.Wrap(in.Factory, in.Create),
		List:   ucdecorator.Wrap(in.Factory, in.List),
	}
}

var Module = fx.Module(
	"<module>",
	fx.Provide(
		// repositories/services/validators
		// raw usecases
		usecase.New<Entity>CreateUseCase,
		usecase.New<Entity>ListUseCase,

		// decorated usecases
		provideDecoratedUseCases,

		// handlers/routers
	),
)

This keeps:

  1. Raw constructors simple
  2. Decoration centralized in one provider
  3. Handler injection strongly typed via ucdecorator.UseCase[Input, Output]

Enforce rules

  1. Depend only on ports.* interfaces in use cases.
  2. Keep orchestration in use case; keep persistence in repositories.
  3. Use a single public Execute method; do not create a private execute wrapper.
  4. Always define both Input and Output structs (use empty struct when needed).
  5. Keep naming consistent across file, structs, constructor, and method.
  6. Return typed output DTOs; do not leak persistence models directly.
  7. Keep observability and translation outside usecases (via decorators).

Final checklist

  1. Create internal/modules/<module>/usecase/<operation>_usecase.go.
  2. Add Input/Output DTOs for the operation (including empty structs when needed).
  3. Inject required ports/services in constructor.
  4. Implement a single Execute with all business logic.
  5. Wire raw usecase in Fx and decorate with ucdecorator.Wrap(factory, raw).
  6. Create unit tests using the go-unit-tests skill.
  7. Run make test.
  8. Run make lint.
  9. Run make nilaway.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.13%
按下载量换算32

Claude

31.04%
按下载量换算28

Cursor

19.87%
按下载量换算18

Gemini CLI

10.18%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills