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核心组件数据库ORMORM链式操作ORM链式操作-主从切换.md

从之前的介绍我们知道 gdb 支持基于应用层的主从配置以及读写分离,并且所有的特性仅需要通过简单的配置即可实现, gdb 内部将会对SQL请求自动地进行主从切换。以下是一个简单的主从配置,包含一主一从:

database:
  default:
  - type: "mysql"
    link: "root:12345678@tcp(192.168.1.1:3306)/test"
    role: "master"
  - type: "mysql"
    link: "root:12345678@tcp(192.168.1.2:3306)/test"
    role: "slave"

在大部分的场景中,我们的写入请求是到 Master 主节点,而读取请求是到 Slave 从节点,这样的好处是能够对数据库的请求进行压力分摊,并提高数据库的可用性。但在某些场景中,我们期望读取操作在 Master 节点上执行,特别是一些对于即时性要求比较高的场景(因为主从节点之间的数据同步是有延迟的)。

开发者可以通过 Master 和 Slave 方法自定义决定当前链式操作执行在哪个节点上。

我们来一个简单的示例。我们有一个订单系统,每天的流量比较大,因此数据库在主从同步时往往会存在 1-500ms 时间的延迟。在业务需求中,创建订单后需要立即展示订单列表页面。可以预料到如果该订单列表页面默认往从节点读取数据的话,很有可能用户在创建订单后在订单列表页面看不到最新创建的订单(因为数据库主从同步延迟)。这个问题,我们可以在订单列表页面设置为往主节点读取数据即可解决。

  1. 在订单创建的时候,没有必要指定操作的节点,因为写入操作默认是在主节点上执行的。为简化示例,我们这里仅展示关键的代码:

    g.Model("order").Data(g.Map{
        "uid"   : 1000,
        "price" : 99.99,
        // ...
    }).Insert()
  2. 在订单列表页面查询时,我们需要使用 Master 方法指定查询操作是在主节点上进行,以避免读取延迟。

    g.Model("order").Master().Where("uid", 1000).All()

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.