Skip to content

Commit 41bd617

Browse files
feat: add GoFrame official skills
1 parent 945d5d4 commit 41bd617

945 files changed

Lines changed: 112548 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/skills/goframe-v2/SKILL.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
name: goframe-v2
3+
description: GoFrame development skill. TRIGGER when writing/modifying Go files, implementing services, creating APIs, or database operations. DO NOT TRIGGER for frontend/shell scripts.
4+
license: Apache-2.0
5+
---
6+
7+
# Critical Conventions
8+
9+
## Project Development Standards
10+
- For complete projects (HTTP/microservices), install GoFrame CLI and use `gf init` to create project scaffolding. See [Project Creation - init](./references/开发工具/项目创建-init.md) for details.
11+
- Auto-generated code files (dao, do, entity) MUST NOT be manually created or modified per GoFrame conventions.
12+
- Unless explicitly requested, do NOT use the `logic/` directory for business logic. Implement business logic directly in the `service/` directory.
13+
- Reference complete project examples:
14+
- HTTP service best practice: [user-http-service](./examples/practices/user-http-service)
15+
- gRPC service best practice: [user-grpc-service](./examples/practices/user-grpc-service)
16+
17+
## Component Usage Standards
18+
- Before creating new methods or variables, check if they already exist elsewhere and reuse existing implementations.
19+
- Use the `gerror` component for all error handling to ensure complete stack traces for traceability.
20+
- When exploring new components, prioritize GoFrame built-in components and reference best practice code from examples.
21+
- **Database Operations MUST use DO objects** (`internal/model/do/`), never `g.Map` or `map[string]interface{}`. DO struct fields are `interface{}`; unset fields remain `nil` and are automatically ignored by the ORM:
22+
```go
23+
// Good - use DO object
24+
dao.Users.Ctx(ctx).Where(cols.Id, id).Data(do.User{Uid: uid}).Update()
25+
26+
// Good - conditional fields, unset fields are nil and ignored
27+
data := do.User{}
28+
if password != "" { data.PasswordHash = hash }
29+
if isAdmin != nil { data.IsAdmin = *isAdmin }
30+
dao.Users.Ctx(ctx).Where(cols.Id, id).Data(data).Update()
31+
32+
// Good - explicitly set a column to NULL using gdb.Raw
33+
dao.Instances.Ctx(ctx).Where(cols.Id, id).Data(do.Instance{IdleSince: gdb.Raw("NULL")}).Update()
34+
35+
// Bad - never use g.Map for database operations
36+
dao.Users.Ctx(ctx).Data(g.Map{cols.Uid: uid}).Update()
37+
```
38+
## Code Style Standards
39+
- **Variable Declarations**: When defining multiple variables, use a `var` block to group them for better alignment and readability:
40+
```go
41+
// Good - aligned and clean
42+
var (
43+
authSvc *auth.Service
44+
bizCtxSvc *bizctx.Service
45+
k8sSvc *svcK8s.Service
46+
notebookSvc *notebook.Service
47+
middlewareSvc *middleware.Service
48+
)
49+
50+
// Avoid - scattered declarations
51+
authSvc := auth.New()
52+
bizCtxSvc := bizctx.New()
53+
k8sSvc := svcK8s.New()
54+
```
55+
- Apply this pattern when you have 3 or more related variable declarations in the same scope.
56+
57+
## Soft Delete & Time Maintenance
58+
59+
GoFrame provides **automatic** soft delete and time maintenance features. When a table contains `created_at`, `updated_at`, or `deleted_at` fields, the ORM handles these automatically.
60+
61+
### Automatic Time Fields
62+
63+
| Field | Auto Behavior |
64+
|-------|---------------|
65+
| `created_at` | Auto-written on `Insert/InsertAndGetId`, never modified afterward |
66+
| `updated_at` | Auto-written on `Insert/Update/Save` |
67+
| `deleted_at` | Auto-written on `Delete` (soft delete), auto-filtered on queries |
68+
69+
### Critical Rules
70+
71+
**1. NEVER manually set time fields** - GoFrame handles these automatically:
72+
```go
73+
// WRONG - redundant manual time setting
74+
dao.User.Ctx(ctx).Data(do.User{
75+
Name: "john",
76+
CreatedAt: gtime.Now(), // REDUNDANT! Framework handles this
77+
UpdatedAt: gtime.Now(), // REDUNDANT! Framework handles this
78+
}).Insert()
79+
80+
// CORRECT - let framework handle time fields
81+
dao.User.Ctx(ctx).Data(do.User{
82+
Name: "john",
83+
}).Insert()
84+
```
85+
86+
**2. NEVER manually add `WhereNull(cols.DeletedAt)`** - GoFrame auto-adds soft delete filter:
87+
```go
88+
// WRONG - redundant soft delete condition
89+
dao.User.Ctx(ctx).
90+
Where(do.User{Status: 1}).
91+
WhereNull(cols.DeletedAt). // REDUNDANT! Framework auto-adds this
92+
Scan(&list)
93+
94+
// CORRECT - framework auto-adds deleted_at IS NULL
95+
dao.User.Ctx(ctx).
96+
Where(do.User{Status: 1}).
97+
Scan(&list)
98+
```
99+
100+
**3. Use `Delete()` for soft delete** - Framework converts to `UPDATE SET deleted_at = NOW()`:
101+
```go
102+
// CORRECT - use Delete(), framework handles soft delete
103+
dao.User.Ctx(ctx).Where(do.User{Id: id}).Delete()
104+
// Actual SQL: UPDATE `sys_user` SET `deleted_at`=NOW() WHERE `id`=?
105+
106+
// WRONG - manual Update with deleted_at
107+
dao.User.Ctx(ctx).
108+
Where(do.User{Id: id}).
109+
Data(do.User{DeletedAt: gtime.Now()}). // REDUNDANT!
110+
Update()
111+
```
112+
113+
### Field Type Support
114+
115+
The `deleted_at` field supports multiple types:
116+
- **DateTime/Timestamp**: Default, stores deletion time
117+
- **Integer**: Stores Unix timestamp (seconds)
118+
- **Boolean**: Stores 0/1 for deleted state
119+
120+
### Configuration (Optional)
121+
122+
Time field names can be customized in `config.yaml`:
123+
```yaml
124+
database:
125+
default:
126+
createdAt: "created_at" # Custom field name
127+
updatedAt: "updated_at"
128+
deletedAt: "deleted_at"
129+
timeMaintainDisabled: false # Set true to disable this feature
130+
```
131+
132+
# GoFrame Documentation
133+
Complete GoFrame development resources covering component design, usage, best practices, and considerations: [GoFrame Documentation](./references/README.MD)
134+
135+
# GoFrame Code Examples
136+
Rich practical code examples covering HTTP services, gRPC services, and various project types: [GoFrame Examples](./examples/README.MD)

0 commit comments

Comments
 (0)