スキル一覧に戻る
griffnb

controller-generation

by griffnb

Techboss Go Backend

0🍴 0📅 2026年1月2日
GitHubで見るManusで実行

SKILL.md


name: controller-generation description: Code generation for CRUD endpoints

Controller Code Generation

The system uses core_generate to automatically create standard CRUD operations for controllers.

Code Generation Command

Add this directive to your setup.go file:

//go:generate core_gen controller Account -modelPackage=account

Parameters:

  • controller - Command type
  • Account - Model name (PascalCase)
  • -modelPackage=account - Package name containing the model
  • -options=admin if its an admin only controller
  • -skip=xxxYYY,aaaBBB skip generating this function because we need to customize it

Generated Files

Running go generate creates two files:

x_gen_admin.go - Admin CRUD handlers:

  • adminIndex - List all resources
  • adminGet - Get single resource
  • adminCreate - Create new resource
  • adminUpdate - Update existing resource
  • adminCount - Get total count

(optionally) x_gen_auth.go - Public CRUD handlers:

  • authIndex - List resources (filtered to user's data)
  • authGet - Get single resource (with ownership check)
  • authCreate - Create new resource
  • authUpdate - Update resource (with ownership check)

Generated Endpoints

MethodAdmin RoutePublic RouteFunctionDescription
GET/admin/account/accountadminIndex, authIndexList resources
GET/admin/account/{id}/account/{id}adminGet, authGetGet single resource
POST/admin/account/accountadminCreate, authCreateCreate new resource
PUT/admin/account/{id}/account/{id}adminUpdate, authUpdateUpdate resource
GET/admin/account/count-adminCountGet total count
GET/admin/account/_ts-TypeScriptTS type generation

Skipping Endpoints

You can disable specific endpoints using the -skip parameter:

//go:generate core_gen controller AiTool -modelPackage=ai_tool -skip=authCreate,authUpdate

This will generate all endpoints except authCreate and authUpdate.

Available Skip Options:

  • adminIndex - Skip admin list endpoint
  • adminGet - Skip admin get endpoint
  • adminCreate - Skip admin create endpoint
  • adminUpdate - Skip admin update endpoint
  • adminCount - Skip admin count endpoint
  • authIndex - Skip public list endpoint
  • authGet - Skip public get endpoint
  • authCreate - Skip public create endpoint
  • authUpdate - Skip public update endpoint

Common Skip Patterns

Read-only public endpoint:

//go:generate core_gen controller Config -modelPackage=config -skip=authCreate,authUpdate

Admin-only resource:

//go:generate core_gen controller SystemLog -modelPackage=system_log -options=admin

Customizing Generated Code

DO NOT edit generated files directly. They will be overwritten on next generation.

Instead, create custom handlers in separate files, name them accordingly auth.go open.go admin.go

if theres lots of functions, group them together by relation then use a prefix, auth_password.go auth_emails.go

custom_handlers.go:

package account

func customSearch(_ http.ResponseWriter, req *http.Request) ([]*account.Account, int, error) {
    // Custom search logic here
    // ...
}

Then wire up in setup.go:

r.Get("/search", helpers.RoleHandler(helpers.RoleHandlerMap{
    constants.ROLE_ANY_AUTHORIZED: helpers.StandardPublicRequestWrapper(customSearch),
}))

Regenerating Code

Re-run generation after:

  • Updating skip parameters
go generate path/to/file

スコア

総合スコア

40/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です