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

:::tip 本章节的示例演示打包/解包的同时也演示了对数据的加密/解密。大部分业务项目其实并不需要加密/解密操作,因此直接使用工具打包即可。 ::: 在上一章节我们介绍通过 gf 工具链进行文件/目录打包,并生成 Go 文件编译到可执行文件中。在本章节中,我们介绍资源管理中涉及到的方法,并通过一个打包/解包二进制资源文件的示例,介绍这些方法实现自定义的打包/解包功能。同时,我们也演示了如何通过自定义加解密来保护我们的资源文件内容。

接口文档:

https://pkg.go.dev/github.com/gogf/gf/v2/os/gres

简要介绍:

  1. 通过 Pack*/ Unpack* 方法可以实现对任意文件的打包/解包功能,可以打包到二进制文件或者Go代码文件。
  2. 资源管理由 Resource 对象实现,可实现对打包内容的添加,文件的检索查找,以及对目录的遍历等功能。
  3. 资源文件由 File 对象实现,该文件对象和 os.File 文件对象类似,并且该对象实现了 http.File 接口。
  4. ScanDir 用于针对于特定目录下的文件/目录检索,并且支持递归检索。
  5. ScanDirFile 用于针对于特定目录下的文件检索,并且支持递归检索。
  6. 通过 Dump 方法在终端打印出 Resource 资源对象所有的文件列表,资源管理器中的文件分隔符号统一为 /。
  7. 此外, gres 资源管理模块提供了默认的 Resource 对象,并通过包方法提供了对该默认对象的操作。

自定义打包示例

我们将项目根目录下的public和config目录打包为data.bin二进制文件,并通过gaes加密算法对生成的二进制内容进行加密。

package main

import (
    "github.com/gogf/gf/v2/crypto/gaes"
    "github.com/gogf/gf/v2/os/gfile"
    "github.com/gogf/gf/v2/os/gres"
)

var (
    CryptoKey = []byte("x76cgqt36i9c863bzmotuf8626dxiwu0")
)

func main() {
    binContent, err := gres.Pack("public,config")
    if err != nil {
        panic(err)
    }
    binContent, err = gaes.Encrypt(binContent, CryptoKey)
    if err != nil {
        panic(err)
    }
    if err := gfile.PutBytes("data.bin", binContent); err != nil {
        panic(err)
    }
}

自定义解包示例

我们使用将刚才打包生成的data.bin,需要解密和解包两步操作。

package main

import (
    "github.com/gogf/gf/v2/crypto/gaes"
    "github.com/gogf/gf/v2/os/gfile"
    "github.com/gogf/gf/v2/os/gres"
)

var (
    CryptoKey = []byte("x76cgqt36i9c863bzmotuf8626dxiwu0")
)

func main() {
    binContent := gfile.GetBytes("data.bin")
    binContent, err := gaes.Decrypt(binContent, CryptoKey)
    if err != nil {
        panic(err)
    }
    if err := gres.Add(binContent); err != nil {
        panic(err)
    }
    gres.Dump()
}

最后,我们使用 gres.Dump() 打印出添加成功的文件列表查看资源文件是否添加成功。

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.