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

我们可以通过gf命令行工具的pack命令实现对任意文件/目录的打包,关于gf命令行工具的安装和使用具体请查看资源打包-pack章节。由于通过命令行工具进行打包比较简便,因此也是推荐的打包方式。

gf pack生成Go文件

比较推荐的方式是将Go文件直接生成到boot启动目录,并设置生成Go文件的包名为boot,这样该资源文件将会被自动引入到项目中。我们将项目的config、public、template三个目录的文件打包到Go文件,打包命令为:

gf pack config,public,template packed/data.go -n packed

生成的Go文件内容类似于:

package packed

import "github.com/gogf/gf/v2/os/gres"

func init() {
    if err := gres.Add("H4sIAAAAAAAC/5y8c5Bl0Zbuu9O2bVaq0rZZ6Urbtm3bNnfatipto9"); err != nil {
        panic(err)
    }
}

可以看到,生成的Go文件中通过gres.Add方法将资源文件的二进制内容添加到默认的资源管理器中,该方法的参数是压缩过后的BASE64字符串,将会在程序启动的时候做解压并在内存中生成一个文件树对象,便于在运行时快速操作文件。

使用打包的Go文件

在boot包中优先引入packed资源包

在项目的boot程序启动设置包中自动引入packed资源包,并且应当作为第一个引入的包,以便于其他引入的包在初始化时(init方法中)便能使用到资源内容,例如像这样(module名称为my-app):

import (
    _ "my-app/packed"

    // 其他包
)

这里建议引入packed包和其他包之间加入一个空行以作区分,特别是Goland IDE的import插件不会将引入包进行自动排序。

在main包中优先引入boot包

由于项目的main入口程序文件会引入boot包,并且应当作为第一个引入的包:

import (
    _ "my-app/boot"

    // 其他包
)

这里建议引入boot包和其他包之间加入一个空行以作区分,特别是Goland IDE的import插件不会将引入包进行自动排序。

随后可以在项目的任何地方使用gres模块来访问打包的资源文件。

如果使用GoFrame推荐的项目目录结构(新建项目),在目录结构中会存在boot目录(对应包名也是boot),用于程序启动设置。因此如果将Go文件生成到boot目录下,那么将会被自动编译进可执行文件中。

打印资源管理文件列表

可以通过gres.Dump()方法打印出当前资源管理器中所有的文件列表,输出内容类似于:

2019-09-15T13:36:28+00:00   0.00B config
2019-07-27T07:26:12+00:00   1.34K config/config.toml
2019-09-15T13:36:28+00:00   0.00B public
2019-06-25T17:03:56+00:00   0.00B public/resource
2018-12-04T12:50:16+00:00   0.00B public/resource/css
2018-12-17T12:54:26+00:00   0.00B public/resource/css/document
2018-12-17T12:54:26+00:00   4.20K public/resource/css/document/style.css
2018-08-24T01:46:58+00:00  32.00B public/resource/css/index.css
2019-05-23T03:51:24+00:00   0.00B public/resource/image
2018-08-20T05:02:08+00:00  24.01K public/resource/image/cover.png
2019-05-23T03:51:24+00:00   4.19K public/resource/image/favicon.ico
2018-08-23T01:44:50+00:00   4.19K public/resource/image/gf.ico
2018-12-04T13:04:34+00:00   0.00B public/resource/js
2019-06-27T11:06:12+00:00   0.00B public/resource/js/document
2019-06-27T11:06:12+00:00  11.67K public/resource/js/document/index.js
2019-09-15T13:36:28+00:00   0.00B template
2019-02-02T09:08:56+00:00   0.00B template/document
2018-12-04T12:49:08+00:00   0.00B template/document/include
2018-12-04T12:49:08+00:00 329.00B template/document/include/404.html
2019-03-06T01:52:56+00:00   3.42K template/document/index.html
...

需要注意的是,在使用资源管理器中的资源文件时,需要严格按照其路径进行检索获取。

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.