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

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

在前面章节中,我们学会了如何开发一个简单的Web Server程序。 在本章节中,我们将会尝试着在Web Server中获取客户端提交的参数信息。 为简化示例,我们使用Query String的方式来传递请求参数。

参数示例

我们将之前的Hello World示例程序进行简单的改造:

package main

import (
    "github.com/gogf/gf/v2/frame/g"
    "github.com/gogf/gf/v2/net/ghttp"
)

func main() {
    s := g.Server()
    s.BindHandler("/", func(r *ghttp.Request) {
        r.Response.Writef(
            "Hello %s! Your Age is %d",
            r.Get("name", "unknown").String(),
            r.Get("age").Int(),
        )
    })
    s.SetPort(8000)
    s.Run()
}

在GoFrame框架中,获取参数非常便捷。在本示例中,我们通过r.Get方法获取客户端提交的参数,该方法能够获取所有HTTP Method提交的参数, 比如Query String/Form/Body等,其内部将会根据客户端提交的类型自动识别解析,比如支持自动识别参数格式例如json/xml等。该方法的定义如下:

func (r *Request) Get(key string, def ...interface{}) *gvar.Var

可以看到,Get方法接受两个参数,第一个为参数名称,第二个参数为非必须参数,表示默认值。返回结果为一个*gvar.Var对象,该对象为GoFrame框架 提供的运行时泛型对象,开发者可以根据业务场景需要将参数转换为各种类型。

执行结果

运行后,我们访问 http://127.0.0.1:8000/?name=john&age=18 可以看到,页面输出结果符合预期。

我们访问 http://127.0.0.1:8000/ 可以看到,页面输出结果同样符合预期。当未传递name参数时,程序将会使用默认值unknown,并且age参数会使用int类型的默认值0。

学习小结

在本章节中,我们学会了如何在HTTP路由函数中获取客户端提交的参数。

但大家可以看到,在本示例的代码中,存在一些显而易见的问题:

  • 参数的接收使用了硬编码的参数名称,如果在真实的项目开发中,很容易由于名称拼写错误引发异常。
  • 硬编码的参数名称不能确定业务含义和数据类型,很难进行长期管理维护,例如难以对参数进行描述说明、类型校验等基本操作。

在下一章节中,我们尝试通过结构化的参数对象来规避这一问题。

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.