Files
xk-of-view/.cursor/rules/20-backend-goframe.mdc
2026-07-18 05:57:07 +08:00

18 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: 萧康云医后端 GoFrame GF 分层开发规则
globs: **/*.go,api/**/*,internal/**/*,manifest/**/*,resource/**/*
alwaysApply: false
---
# 后端规则
- 后端使用 GoFrame GF 框架,必须遵循 GF 的项目结构、路由注册、控制器、服务、模型、配置和错误处理规范。
- 分层链路为:路由 -> 控制器 -> service 服务层 -> 模型层。
- 路由层只负责请求路径、HTTP 方法、中间件和控制器绑定,不编写业务逻辑。
- 控制器层负责获取请求信息、参数验证、用户信息解析、调用 service并返回统一响应。
- 控制器层不编写核心业务逻辑,不直接操作数据库,不绕过 service 调用模型。
- service 层是业务逻辑层,负责业务流程编排、权限判断、事务控制、数据处理和外部服务调用。
- 模型层只用于定义表结构、表关系、字段映射和数据承载,不编写业务逻辑。
- 数据库访问、事务、缓存、队列、第三方接口等能力应按 GF 推荐方式封装,并放在合适的服务或基础设施模块中。
- 参数校验、错误码、日志、上下文传递和用户身份解析要保持统一规范。