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开发工具代码生成-gen枚举维护-gen enums.md

:::tip 该功能特性为 实验性特性,从 v2.4 版本开始提供。 :::

基本介绍

该命令用于分析指定代码目录源码,按照规范生成枚举值信息以及 Go 代码文件, 主要用以完善 OpenAPIv3 文档中的枚举值维护。

解决痛点

痛点描述

  • API 文档中枚举值类型参数不展示枚举值可选项的问题。
  • API 文档中的枚举值维护困难的问题,代码与文档脱离维护的问题。降低了与调用端,特别是前后端的协作效率

例如,以下接口定义中,任务包含多种状态,这些状态都是枚举值,如果后端来维护成本比较高,并且容易遗漏状态的维护,造成状态枚举值不完整。

痛点解决

通过工具解析源码,将枚举值解析生成到启动包 Go 文件中,在服务运行时自动加载枚举值,降低手工维护成本,避免枚举值遗漏维护问题。

例如,在以下接口定义中,通过工具来维护枚举值,提高了开发效率。

命令使用

$ gf gen enums -h
USAGE
    gf gen enums [OPTION]

OPTION
    -s, --src        source folder path to be parsed
    -p, --path       output go file path storing enums content
    -x, --prefixes   only exports packages that starts with specified prefixes
    -h, --help       more information about this command

EXAMPLE
    gf gen enums
    gf gen enums -p internal/boot/boot_enums.go
    gf gen enums -p internal/boot/boot_enums.go -s .
    gf gen enums -x github.com/gogf

参数说明:

名称 必须 默认值 含义
src 否 . 指定分析的源码目录路径,默认为当前项目根目录
path 否 internal/boot/boot_enums.go 指定生成的枚举值注册Go代码文件路径
prefixes 否 - 只会生成包名称前缀的带有指定关键字的枚举值,支持多个前缀配置

:::info 该命令底层使用了AST解析实现,将会递归分析所有依赖包的enums定义。如果业务项目依赖较复杂,生成enums可能会比较多,但绝大部分时候我们只关心自身项目或者个别依赖包的enums定义,那么这个时候可以使用prefixes参数来控制只生成特定包名前缀的enums。 :::

工具配置项yaml格式示例:

gfcli:
  gen:
    enums:
      src:  "api"
      path: "internal/boot/boot_enums.go"
      prefixes: 
      - github.com/gogf
      - myexample/project

生成文件的使用

执行 gf gen enums 命令生成枚举分析文件 internal/boot/boot_enums.go,生成文件之后,需要在项目入口文件匿名引入:

import (
    _ "项目模块名/internal/boot"
)

扩展阅读

如何规范定义枚举值

请参考章节: Golang枚举值管理

如何对枚举值进行校验

如果规范化定义了枚举值,并且通过命令生成了枚举值维护文件,那么在参数校验中可以使用 enums 规则对枚举值字段进行校验,具体规则介绍请参考章节: 数据校验-校验规则

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.