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.

referencesWEB服务开发分页管理分页管理.md

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

:::warning 废弃提示 从版本v2.10.0开始,gpage组件已被标记为废弃,将在未来版本中被移除。

推荐替代方案:

  1. 使用ORM分页功能:GoFrame的gdb ORM组件提供了完善的分页支持
  2. 自定义分页逻辑:根据业务需求实现分页,前端使用现代化的UI组件库
  3. API分页:返回分页数据结构,由前端框架处理分页显示 :::

基本介绍

分页管理由 gpage 模块实现, gpage 提供了强大的动态分页及静态分页功能,并且为开发者自定义分页样式提供了极高的灵活度。 :::tip gpage 模块主要用于生成分页的HTML代码,常用于 MVC 开发场景。 ::: 使用方式:

import "github.com/gogf/gf/v2/util/gpage"

接口文档:

https://pkg.go.dev/github.com/gogf/gf/v2/util/gpage

分页对象:

// Page is the pagination implementer.
// All the attributes are public, you can change them when necessary.
type Page struct {
    TotalSize      int    // Total size.
    TotalPage      int    // Total page, which is automatically calculated.
    CurrentPage    int    // Current page number >= 1.
    UrlTemplate    string // Custom url template for page url producing.
    LinkStyle      string // CSS style name for HTML link tag <a>.
    SpanStyle      string // CSS style name for HTML span tag <span>, which is used for first, current and last page tag.
    SelectStyle    string // CSS style name for HTML select tag <select>.
    NextPageTag    string // Tag name for next p.
    PrevPageTag    string // Tag name for prev p.
    FirstPageTag   string // Tag name for first p.
    LastPageTag    string // Tag name for last p.
    PrevBarTag     string // Tag string for prev bar.
    NextBarTag     string // Tag string for next bar.
    PageBarNum     int    // Page bar number for displaying.
    AjaxActionName string // Ajax function name. Ajax is enabled if this attribute is not empty.
}

创建分页对象

由于分页对象往往是在 Web 服务中使用,因此从框架 v1.12 版本开始,我们提供更加便捷的分页对象创建方式,分页对象集成到了 ghttp.Request 对象上,可以非常方便地通过 Request.GetPage 方法获取分页对象。该方法定义如下:

func (r *Request) GetPage(totalSize, pageSize int) *gpage.Page

可以看到,获取分页对象仅需要传递总数量及分页数量即可。当然,分页对象也可以独立使用,由于篇幅有限,我们这里只介绍最常用且最简便的使用方式。

具体使用示例请查看后续章节。

预定义分页样式

方法 GetContent 提供了预定义的常见的分页样式,以便于开发者快速使用。当预定义的样式无法满足开发者需求时,开发者可以使用公开的方法来自定义分页样式(或者进行方法重载来实现自定义),也可以使用正则替换指定预定义的分页样式中的部分内容来实现自定义。

具体使用示例请查看后续章节。

使用 Ajax 分页功能

分页对象的 AjaxActionName 属性用于给定一个 Ajax 方法名,用于实现 Ajax 分页,但是需要注意的是,该 Ajax 方法名称需要前后端约定统一,并且该 Ajax 方法只有一个URL参数。以下是一个 Ajax 方法的客户端定义示例:

function DoAjax(url) {
    // 这里读取URL的内容并根据业务逻辑进行内容展示
}

具体使用示例请查看后续章节。

相关文档

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.