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

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

Server 对象支持通过配置文件进行便捷的配置。支持的配置选项以及配置说明请查看接口文档说明,文档中有详细说明,以下章节不会对配置选项作介绍。

当使用 g.Server(单例名称) 获取 Server 单例对象时,将会自动通过默认的配置管理对象获取对应的 Server 配置。默认情况下会读取 server.单例名称 配置项,当该配置项不存在时,将会读取 server 配置项。

支持的配置文件配置项请参考 Server 配置管理对象属性: https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#ServerConfig

示例1,默认配置项

server:
    address:    ":80"
    serverRoot: "/var/www/Server"

随后可以使用 g.Server() 获取默认的单例对象时自动获取并设置该配置。 :::warning 在没有配置 address 的情况下, http server 将会使用本地网卡的所有 ip 地址加上 随机空闲端口 来启动(默认配置 :0)。如果想要指定 ip 但是使用随机空闲端口启动 http server,可以使用 ip:0 的格式来配置 address,例如: 192.168.1.1:0, 10.0.1.1:0。 :::

示例2,多个配置项

多个 Server 的配置示例:

server:
    address:    ":80"
    serverRoot: "/var/www/Server"
    server1:
        address:    ":8080"
        serverRoot: "/var/www/Server1"
    server2:
        address:    ":8088"
        serverRoot: "/var/www/Server2"

我们可以通过单例对象名称获取对应配置的 Server 单例对象:

// 对应 server.server1 配置项
s1 := g.Server("server1")
// 对应 server.server2 配置项
s2 := g.Server("server2")
// 对应默认配置项 server
s3 := g.Server("none")
// 对应默认配置项 server
s4 := g.Server()

示例3,较完整示例

比如上一个章节的示例,对应的配置文件如下:

server:
    address:          ":8199"
    serverRoot:       "/var/www/Server"
    indexFiles:       ["index.html", "main.html"]
    accessLogEnabled: true
    errorLogEnabled:  true
    pprofEnabled:     true
    logPath:          "/var/log/ServerLog"
    sessionIdName:    "MySessionId"
    sessionPath:      "/tmp/MySessionStoragePath"
    sessionMaxAge:    "24h"
    dumpRouterMap:    false

同理,配置属性项的名称也不区分大小写,单词间也支持使用 -/ _ 符号连接。也就是说以下配置文件效果和上面的配置文件一致:

server:
    address:          ":8199"
    serverRoot:       "/var/www/Server"
    indexFiles:       ["index.html", "main.html"]
    accessLogEnabled: true
    errorLogEnabled:  true
    pprofEnabled:     true
    log-path:         "/var/log/ServerLog"
    session_Id_Name:  "MySessionId"
    Session-path:     "/tmp/MySessionStoragePath"
    session_MaxAge:   "24h"
    DumpRouterMap:    false

:::tip 我们推荐配置文件中的配置项名称统一使用小驼峰的格式。 :::

上传限制

Server 对于客户端提交的数据是由大小限制的,主要有两个配置参数控制:

  • MaxHeaderBytes:请求头大小限制,请求头包括客户端提交的 Cookie 数据,默认设置为 10KB。
  • ClientMaxBodySize:客户端提交的 Body 大小限制,同时也影响文件上传大小,默认设置为 8MB。

由于安全性的考虑,默认的上传限制都不是很高,特别是 ClientMaxBodySize 的大小限制,在需要文件上传的场景可适当考虑调整,通过配置文件配置即可,例如:

server:
    maxHeaderBytes:    "20KB"
    clientMaxBodySize: "200MB"

这样便修改请求头大小限制为 20KB,文件上传大小限制为 200MB。如果不想做上传大小做任何限制,那么将 clientMaxBodySize 设置为 0 即可。

日志配置

从 v2 版本开始, Server 增加了对配置文件中 Logger 的配置项支持,主要是为了统一日志组件配置、并解决日志滚动切分的问题。配置示例:

server:
    address: ":8080"
    logger:
        path:                 "/var/log/server"
        file:                 "{Y-m-d}.log"
        stdout:               false
        rotateSize:           "100M"
        rotateBackupLimit:    10
        rotateBackupExpire:   "60d"
        rotateBackupCompress: 9
        rotateCheckInterval:  "24h"

关于其中 logger 项的详细介绍请参考 日志组件-配置管理 章节。

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.