All skills
gogf avatar

/goframe-v2

@911705d
by GoFramegogf/skills81 stars
3

GoFrame v2 development skill. Use only when the target Go project uses or is explicitly adopting GoFrame v2: the nearest go.mod requires github.com/gogf/gf/v2, existing Go files import github.com/gogf/gf/v2 or any github.com/gogf/gf/v2/... component package, or the user asks to scaffold, migrate, or build with GoFrame. Trigger for GoFrame-backed Go work such as APIs/controllers/services, middleware, routing/config, ORM/DAO/DO/entity/database operations, gf CLI/codegen, HTTP/gRPC services, and microservice conventions. Do not trigger for generic Go projects without GoFrame evidence, frontend-only work, shell scripts, or unrelated infrastructure tasks.

Use this Skill: https://skilld.dev/gh/gogf/skills/goframe-v2

This session only. Nothing lands on disk.

references微服务开发工程管理.md

≈759 tokens on demand. Your agent reads this file only when SKILL.md points to it.

基本介绍

基于微服务开发的工程目录采用统一的框架工程目录结构,具体请参考章节: 工程目录设计🔥

我们这里以项目 https://github.com/gogf/gf-demo-grpc 为例说明。

协议文件

协议文件定义在 manifest/protobuf 目录下。协议文件的目录路径遵循规则: 模块名/版本号/xxx.proto,其中版本号采用 v1/ v2 的形式进行管理,便于维护接口的版本兼容性。

其中,涉及数据表结构的 protobuf 文件,由框架开发工具自动生成后存放在 manifest/pbentity 目录下。

接口文件

通过 proto 协议文件编译生成的接口文档统一存放在 api 目录下。

开发工具

生成数据表结构

我们可以通过 gf gen pbentity 命令(或使用 make pbentity )自动根据数据库中的数据表结构生成对应的 protobuf 协议文件。该命令会读取数据库表结构信息,并自动生成符合 protobuf 规范的消息定义文件。命令详细介绍请参考章节: 数据表PB-gen pbentity

编译 proto 协议文件

框架提供了 gf gen pb 命令(或使用 make pb )自动编译 proto 协议文件,并生成对应的接口文件以及控制器文件。该命令会扫描项目中的所有 proto 文件,使用 protoc 编译器生成 Go 语言的 gRPC 接口代码,并自动创建对应的控制器模板文件。

服务的启动

服务的启动控制通过 cmd 目录进行维护,例如: https://github.com/gogf/gf-demo-grpc/blob/main/internal/cmd/cmd.go

在 cmd 文件中,我们需要初始化 gRPC 服务器,配置服务地址和端口,并注册所有的服务实现。

接口的实现与注册

控制器用于实现 proto 文件中定义的接口。控制器文件可以通过 gf gen pb 命令自动生成,同时会自动生成 Register 方法,该方法用于将具体的接口实现注册到 gRPC 服务对象中。

注册方法示例:

在服务启动时进行注册:

标签注入与数据校验

标签自动注入

使用 gf gen pb 命令(或 make pb )进行 proto 文件编译时,支持自动的标签注入功能。只需要通过注释的形式写到 proto 文件中,这些注释将会自动作为 dc 标签嵌入到生成的结构体属性中。如果注释规则形如 xxx:yyy,那么将会自动生成对应的 xxx 标签。例如:

生成后的结构体将包含相应的标签:

需要注意,在 gRPC 协议中,由于输入输出均采用结构体形式,因此无法实现像 HTTP 服务那样的默认值特性。

数据校验插件

数据校验插件会根据标签中设置的规则对请求进行自动校验。该插件需要在服务端通过拦截器的形式手动引入:

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk MEDIUM
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive development guide and code examples for the GoFrame v2 framework. While highly informative for Go developers, it contains several examples with hardcoded placeholder secrets, tokens, and specific local file paths to sensitive configuration files (like Kubernetes credentials). These elements are provided for demonstration purposes but represent insecure practices if used in production without modification.

  • Socket16d

    5 alerts: gptSecurity, gptAnomaly

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    227/949 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 911705d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 months ago.

Steadyupdated 4 months ago
  • Go
  • Database
  • goframe
  • orm
  • http
  • grpc
  • microservices
  • crud
  • scaffolding
  • middleware

README badge

README badge for gogf/skills

Provides instruction and conventions for developing with GoFrame v2, a modular Go framework for building HTTP and gRPC services, microservices, and database operations using its ORM, CLI tooling, and project scaffolding. Use this skill when the target project has GoFrame v2 as a dependency or when the user requests scaffolding, migrations, or service development with GoFrame conventions.

Generated from the current SKILL.md.

When should I use this skill?
Use this skill only when your Go project uses GoFrame v2, indicated by github.com/gogf/gf/v2 in go.mod or imports. Do not use for generic Go projects, frontend work, or infrastructure tasks unrelated to GoFrame.
Should I manually set created_at and updated_at fields?
No. GoFrame automatically writes created_at on insert and updated_at on insert/update/save. Manually setting these fields is redundant and violates project conventions.
What should I use for database operations instead of g.Map?
Always use DO objects from internal/model/do/. DO struct fields are interface{}, unset fields remain nil and are automatically ignored by the ORM.
How does soft delete work in GoFrame?
Call Delete() on the DAO; GoFrame automatically converts it to UPDATE SET deleted_at = NOW(). Queries automatically filter out soft-deleted rows without requiring manual WhereNull conditions.
Where should I implement business logic?
Implement business logic directly in the service/ directory. Do not use the logic/ directory unless explicitly requested.

Generated from the current SKILL.md. These answers refresh after source changes.