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组件列表系统相关时间管理-gtime时间管理-时间对象.md

时间对象

创建 gtime.Time 对象可以通过标准库 time.Time 对象、Unix时间戳、时间字符串(如: 2018-07-18 12:01:00)、自定义时间字符串(需要给定格式,支持自定义格式及标准库格式)。

创建对象

可以通过 gtime.New 方法创建 gtime.Time 对象,该方法支持 time.Time、时间戳、时间字符串创建对象。其中时间戳支持到纳秒的时间整型长度。 例如:

// 通过时间字符串创建
gtime.New("2020-10-24 12:00:00")
// 通过time.Time对象创建
gtime.New(time.Now())
// 通过时间戳(秒)创建
gtime.New(1603710586)
// 通过时间戳(纳秒)创建
gtime.New(1603710586660409000)

此外,时间字符串支持常见时间类型,例如:

2017-12-14 04:51:34 +0805 LMT
2017-12-14 04:51:34 +0805 LMT
2006-01-02T15:04:05Z07:00
2014-01-17T01:19:15+08:00
2018-02-09T20:46:17.897Z
2018-02-09 20:46:17.897
2018-02-09T20:46:17Z
2018-02-09 20:46:17
2018/10/31 - 16:38:46
2018-02-09
2018.02.09

01-Nov-2018 11:50:28
01/Nov/2018 11:50:28
01.Nov.2018 11:50:28
01.Nov.2018:11:50:28
日期连接符号支持'-'、'/'、'.'

使用示例

示例1,自定义格式化语法

package main

import (
    "fmt"
    "github.com/gogf/gf/v2/os/gtime"
)

func main() {
    formats := []string{
        "Y-m-d H:i:s.u",
        "D M d H:i:s T O Y",
        "\\T\\i\\m\\e \\i\\s: h:i:s a",
        "2006-01-02T15:04:05.000000000Z07:00",
    }
    t := gtime.Now()
    for _, f := range formats {
        fmt.Println(t.Format(f))
    }
}

在该示例中,我们给定了四种 format 格式,并将当前时间用这四种格式转换后打印出来。执行后,输出结果如下:

2018-07-22 11:17:13.797
Sun Jul 22 11:17:13 CST +0800 2018
Time is: 11:17:13 am
2006-01-02CST15:04:05.000000000Z07:00

可以看到,这个示例演示了几个需要注意的地方:

  1. 如果使用的字母与格式化字符冲突时,可以使用 \ 符号转义该字符,这样时间格式解析器会认为该字符不是格式化字符,而是普通字母。因此这里的第三个字符串示例输出为: Time is: 11:17:13 am
  2. 使用 Format 方法接收的是自定义的时间格式化语法(如: Y-m-d H:i:s),而非标准库的时间格式语法(如: 2006-01-02 15:04:05),因此在这里的第四个字符串示例中原样输出参数值;

示例2,标准库格式化语法

package main

import (
    "fmt"
    "github.com/gogf/gf/v2/os/gtime"
)

func main() {
    formats := []string{
        "2006-01-02 15:04:05.000",
        "Mon Jan _2 15:04:05 MST 2006",
        "Time is: 03:04:05 PM",
        "2006-01-02T15:04:05.000000000Z07:00 MST",
    }
    t := gtime.Now()
    for _, f := range formats {
        fmt.Println(t.Layout(f))
    }
}

在该示例中,我们使用四种标准库的时间格式化语法格式化当前的时间并输出结果到终端。执行后,输出结果为:

2018-07-22 11:28:13.945
Sun Jul 22 11:28:13 CST 2018
Time is: 11:28:13 AM
2018-07-22T11:28:13.945153275+08:00 CST

有几个需要说明的地方:

  1. 自定义时间格式化语法与标准库时间格式化语法并不冲突,前者使用 Format 方法,后者使用 Layout 方法行格式化,相互独立,互不冲突,无法混用;
  2. 标准库的时间格式化语法自有特点,是不是感觉有点复杂;

示例3,时间对象链式操作

package main

import (
    "fmt"
    "github.com/gogf/gf/v2/os/gtime"
    "time"
)

func main() {
    // 去年今日,系统时间
    fmt.Println(gtime.Now().AddDate(-1, 0, 0).Format("Y-m-d"))

    // 去年今日,UTC时间
    fmt.Println(gtime.Now().AddDate(-1, 0, 0).Format("Y-m-d H:i:s T"))
    fmt.Println(gtime.Now().AddDate(-1, 0, 0).UTC().Format("Y-m-d H:i:s T"))

    // 下个月1号凌晨0点整
    fmt.Println(gtime.Now().AddDate(0, 1, 0).Format("Y-m-01 00:00:00"))

    // 1个小时前
    fmt.Println(gtime.Now().Add(-time.Hour).Format("Y-m-d H:i:s"))
}

执行后,输出结果为:

2020-09-19
2020-09-19 15:51:48 CST
2020-09-19 07:51:48 UTC
2021-10-01 00:00:00
2021-09-19 14:51:48

该示例比较简单,便不多赘述。

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.