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

plus/minus/times/divide

函数 说明 格式 示例 备注
plus 加 {{.value1 | plus .value2}} {{2 | plus 3}} => 5 3+2
minus 减 {{.value1 | minus .value2}} {{2 | minus 3}} => 1 3-2
times 乘 {{.value1 | times .value2}} {{2 | times 3}} => 6 3*2
divide 除 {{.value1 | divide .value2}} {{2 | divide 3}} => 1.5 3/2

text

{{.value | text}}

将value变量值去掉HTML标签,仅显示文字内容(并且去掉script标签)。示例:

{{"<div>测试</div>"|text}}
// 输出: 测试

htmlencode/encode/html

{{.value | htmlencode}}
{{.value | encode}}
{{.value | html}}

将value变量值进行html转义。示例:

{{"<div>测试</div>"|html}}
// 输出: &lt;div&gt;测试&lt;/div&gt;

htmldecode/decode

{{.value | htmldecode}}
{{.value | decode}}

将 value 变量值进行html反转义。 示例:

{{"&lt;div&gt;测试&lt;/div&gt;" | htmldecode}}
// 输出: <div>测试</div>

urlencode/url

{{.url | url}}

将 url 变量值进行 url 转义。 示例:

{{"https://goframe.org" | url}}
// 输出: https%3A%2F%2Fgoframe.org

urldecode

{{.url | urldecode}}

将 url 变量值进行 url 反转义。 示例:

{{"https%3A%2F%2Fgoframe.org"|urldecode}}
// 输出: https://goframe.org

date

{{.timestamp | date .format}}
{{date .format .timestamp}}
{{date .format}}

将timestamp时间戳变量进行时间日期格式化,类似PHP的date方法,format参数支持PHP date方法格式,亦可参考时间管理-gtime。

当timestamp变量为空(或者0)时,表示以当前时间作为时间戳参数执行打印。

示例:

{{1540822968 | date "Y-m-d"}}
{{"1540822968" | date "Y-m-d H:i:s"}}
{{date "Y-m-d H:i:s"}}
// 输出:
// 2018-10-29
// 2018-10-29 22:22:48
// 2018-12-05 10:22:00

compare

{{compare .str1 .str2}}
{{.str2 | compare .str1}}

将str1和str2进行字符串比较,返回值:

  • 0 : str1 == str2
  • 1 : str1 > str2
  • -1 : str1 < str2

示例:

{{compare "A" "B"}}
{{compare "1" "2"}}
{{compare 2 1}}
{{compare 1 1}}
// 输出:
// -1
// -1
// 1
// 0

replace

{{.str | replace .search .replace}}
{{replace .search .replace .str}}

将str中的search替换为replace。示例:

{{"I'm中国人" | replace "I'm" "我是"}}
// 输出:
// 我是中国人

substr

{{.str | substr .start .length}}
{{substr .start .length .str}}

将str从start索引位置(索引从0开始)进行字符串截取length,支持中文,类似PHP的substr函数。示例:

{{"我是中国人" | substr 2 -1}}
{{"我是中国人" | substr 2  2}}
// 输出:
// 中国人
// 中国

strlimit

{{.str | strlimit .length .suffix}}

将str字符串截取length长度,支持中文,超过长度则追加suffix字符串到末尾。示例:

{{"我是中国人" | strlimit 2  "..."}}
// 输出:
// 我是...

concat

{{concat .str1 .str2 .str3...}}

拼接字符串。 示例:

{{concat "我" "是" "中" "国" "人"}}
// 输出:
// 我是中国人

hidestr

{{.str | hidestr .percent .hide}}

将str字符串按照percent百分比从字符串中间向两边隐藏字符(主要用于姓名、手机号、邮箱地址、身份证号等的隐藏),隐藏字符由hide变量定义。支持中文,支持email格式。示例:

{{"热爱GF热爱生活" | hidestr 20  "*"}}
{{"热爱GF热爱生活" | hidestr 50  "*"}}
// 输出:
// 热爱GF*爱生活
// 热爱****生活

highlight

{{.str | highlight .key .color}}

将 str 字符串中的关键字 key 按照定义的颜色 color 进行前置颜色高亮。 示例:

{{"热爱GF热爱生活" | highlight "GF" "red"}}
// 输出:
// 热爱<span style="color:red;">GF</span>热爱生活

toupper/tolower

{{.str | toupper}}
{{.str | tolower}}

将 str 字符串进行大小写转换。 示例:

{{"gf" | toupper}}
{{"GF" | tolower}}
// 输出:
// GF
// gf

nl2br

{{.str | nl2br}}

将 str 字符串中的 \n/\r 替换为html中的 <br /> 标签。 示例:

{{"Go\nFrame" | nl2br}}
// 输出:
// Go<br />Frame

dump

{{dump .var}}

格式化打印变量,功能类似于 g.Dump 方法,常用于开发调试。 示例:

gview.Assign("var", g.Map{
    "name" : "john",
})
{{dump .var}}
// 输出:
// <!--
// {
//     name: "john"
// }
// -->

map

{{map .var}}

将模板变量转换为 map[string]interface{} 类型,常用于 range...end 遍历。

maps

{{maps .var}}

将模板变量转换为 []map[string]interface{} 类型,常用于 range...end 遍历。

json/xml/ini/yaml/yamli/toml

函数 说明 格式
json 将模板变量转换为 JSON 格式字符串。 {{json .var}}
xml 将模板变量转换为 XML 格式字符串。 {{xml .var}}
ini 将模板变量转换为 INI 格式字符串。 {{ini .var}}
yaml 将模板变量转换为 YAML 格式字符串。 {{yaml .var}}
yamli 将模板变量转换为带有自定义缩进的 YAML 格式字符串。 {{yamli .var .indent}}
toml 将模板变量转换为 TOML 格式字符串。 {{toml .var}}

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.