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

接口文档:

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

方法比较简单,比较常用的是以下几个方法:

  1. Timestamp 用于获得当前时间戳, TimestampMilli、 TimestampMicro 及 TimestampNano 用于获得当前的毫秒、微秒和纳秒值。
  2. Date 和 Datetime 用于获得当前日期及当前日期时间。
  3. SetTimeZone 用于设置当前进程的全局时区。
  4. 其他方法说明请查看接口文档。

示例1,基本使用

创建时间对象及获取当前时间戳。

package main

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

func main() {
    fmt.Println("Date       :", gtime.Date())
    fmt.Println("Datetime   :", gtime.Datetime())
    fmt.Println("Second     :", gtime.Timestamp())
    fmt.Println("Millisecond:", gtime.TimestampMilli())
    fmt.Println("Microsecond:", gtime.TimestampMicro())
    fmt.Println("Nanosecond :", gtime.TimestampNano())
}

执行后,输出结果为:

Date       : 2018-07-22
Datetime   : 2018-07-22 11:52:22
Second     : 1532231542
Millisecond: 1532231542688
Microsecond: 1532231542688688
Nanosecond : 1532231542688690259

示例2, StrToTime

除了通过 New 方法外,也可以通过 StrToTime 根据常见的时间字符串解析生成 gtime.Time 对象,常见的时间字符串如下:

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
日期连接符号支持'-'、'/'、'.'

使用示例:

package main

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

func main() {
    array := []string{
        "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.02.09 20:46:17",
        "2018-02-09",
        "2017/12/14 04:51:34 +0805 LMT",
        "2018/02/09 12:00:15",
        "01/Nov/2018:13:28:13 +0800",
        "01-Nov-2018 11:50:28 +0805 LMT",
        "01-Nov-2018T15:04:05Z07:00",
        "01-Nov-2018T01:19:15+08:00",
        "01-Nov-2018 11:50:28 +0805 LMT",
        "01/Nov/2018 11:50:28",
        "01/Nov/2018:11:50:28",
        "01.Nov.2018:11:50:28",
        "01/Nov/2018",
    }
    cstLocal, _ := time.LoadLocation("Asia/Shanghai")
    for _, s := range array {
        if t, err := gtime.StrToTime(s); err == nil {
            fmt.Println(s)
            fmt.Println(t.UTC().String())
            fmt.Println(t.In(cstLocal).String())
        } else {
            glog.Error(s, err)
        }
        fmt.Println()
    }
}

在这个示例中,将部分时间格式串使用 StrToTime 方法转换为 gtime.Time 对象,并输出该事件的 UTC 时间和 CST 时间(上海时区时间)。 执行后,输出结果为:

2017-12-14 04:51:34 +0805 LMT
2017-12-13 20:46:34
2017-12-14 04:46:34 +0800 CST

2006-01-02T15:04:05Z07:00
2006-01-02 22:04:05
2006-01-03 06:04:05 +0800 CST

2014-01-17T01:19:15+08:00
2014-01-16 17:19:15
2014-01-17 01:19:15 +0800 CST

2018-02-09T20:46:17.897Z
2018-02-09 20:46:17
2018-02-10 04:46:17.897 +0800 CST

2018-02-09 20:46:17.897
2018-02-09 12:46:17
2018-02-09 20:46:17.897 +0800 CST

2018-02-09T20:46:17Z
2018-02-09 20:46:17
2018-02-10 04:46:17 +0800 CST

2018-02-09 20:46:17
2018-02-09 12:46:17
2018-02-09 20:46:17 +0800 CST

2018.02.09 20:46:17
2018-02-09 12:46:17
2018-02-09 20:46:17 +0800 CST

2018-02-09
2018-02-08 16:00:00
2018-02-09 00:00:00 +0800 CST

2017/12/14 04:51:34 +0805 LMT
2017-12-13 20:46:34
2017-12-14 04:46:34 +0800 CST

2018/02/09 12:00:15
2018-02-09 04:00:15
2018-02-09 12:00:15 +0800 CST

01/Nov/2018:13:28:13 +0800
2018-11-01 05:28:13
2018-11-01 13:28:13 +0800 CST

01-Nov-2018 11:50:28 +0805 LMT
2018-11-01 03:45:28
2018-11-01 11:45:28 +0800 CST

01-Nov-2018T15:04:05Z07:00
2018-11-01 22:04:05
2018-11-02 06:04:05 +0800 CST

01-Nov-2018T01:19:15+08:00
2018-10-31 17:19:15
2018-11-01 01:19:15 +0800 CST

01-Nov-2018 11:50:28 +0805 LMT
2018-11-01 03:45:28
2018-11-01 11:45:28 +0800 CST

01/Nov/2018 11:50:28
2018-11-01 03:50:28
2018-11-01 11:50:28 +0800 CST

01/Nov/2018:11:50:28
2018-11-01 03:50:28
2018-11-01 11:50:28 +0800 CST

01.Nov.2018:11:50:28
2018-11-01 03:50:28
2018-11-01 11:50:28 +0800 CST

01/Nov/2018
2018-10-31 16:00:00
2018-11-01 00:00:00 +0800 CST

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.