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

:::tip 以下常用方法列表,文档更新可能滞后于代码新特性,更多的方法及示例请参考代码文档: https://pkg.go.dev/github.com/gogf/gf/v2/os/gtime :::

New

  • 说明: New 创建并返回一个具有给定参数的 Time 对象。
  • 格式:
func New(param ...interface{}) *Time
  • 示例:创建时间对象。
func ExampleNew() {
      t1 := gtime.New(time.Now())
      t2 := gtime.New("2018-08-08 08:08:08")
      t3 := gtime.New(1533686888)

      fmt.Println(t1)
      fmt.Println(t2)
      fmt.Println(t3)

      // Output:
      // 2021-11-18 14:18:27
      // 2018-08-08 08:08:08
      // 2018-08-08 08:08:08

Now

  • 说明: Now 创建并返回一个当前时间对象。
  • 格式:
func Now() *Time
  • 示例:获取当前时间对象。
func ExampleNow() {
      t := gtime.Now()
      fmt.Println(t)

      // Output:
      // 2021-11-06 13:41:08
}

Format

  • 说明: 格式化输出时间
  • 格式:
func (t *Time) Format(format string) string
func ExampleTime_Format() {
      gt1 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.Format("Y-m-d"))
      fmt.Println(gt1.Format("l"))
      fmt.Println(gt1.Format("F j, Y, g:i a"))
      fmt.Println(gt1.Format("j, n, Y"))
      fmt.Println(gt1.Format("h-i-s, j-m-y, it is w Day z"))
      fmt.Println(gt1.Format("D M j G:i:s T Y"))

      // Output:
      // 2018-08-08
      // Wednesday
      // August 8, 2018, 8:08 am
      // 8, 8, 2018
      // 08-08-08, 8-08-18, 0831 0808 3 Wedam18 219
      // Wed Aug 8 8:08:08 CST 2018
}

String

  • 说明:  输出字符串
  • 格式:
func (t *Time) String() string
  • 示例:输出字符串类型。
func ExampleTime_String() {
      gt := gtime.New("2018-08-08 08:08:08")
      t1 := gt.String()

      fmt.Println(t1)
      fmt.Println(reflect.TypeOf(t1))

      // Output:
      // 2018-08-08 08:08:08
      // string
}

Timestamp

  • 说明:  获取当前对象的秒时间戳。相应的还有 TimestampMicro/TimestampMilli/TimestampNano。
  • 格式:
func (t *Time) Timestamp() int64
func Timestamp() int64
  • 示例:获取当前对象的秒时间戳。
func ExampleTime_Timestamp() {
      t := gtime.Now()

      fmt.Println(t.Timestamp())
      fmt.Println(gtime.Timestamp())
      fmt.Println(t.TimestampMicro())
       fmt.Println(t.TimestampMilli())
      fmt.Println(t.TimestampNano())

      // Output:
      // 1533686888
      // 1533686888
      // 1533686888000
      // 1533686888000000
      // 1533686888000000000
}

ToZone

  • 说明:  设置时区。
  • 格式:
func (t *Time) ToZone(zone string) (*Time, error)
  • 示例:获取当前对象的秒时间戳。
func ExampleTime_ToZone() {
      gt1 := gtime.Now()
      gt2, _ := gt1.ToZone("Asia/Shanghai")
      gt3, _ := gt1.ToZone("Asia/Tokyo")

      fmt.Println(gt2)
      fmt.Println(gt3)

      // May Output:
      // 2021-11-11 17:10:10
      // 2021-11-11 18:10:10
}

SetTimeZone

  • 说明:  设置时区。
  • 格式:
func SetTimeZone(zone string) error
  • 示例: 设置时区。
func ExampleSetTimeZone() {
      gtime.SetTimeZone("Asia/Shanghai")
      fmt.Println(gtime.Datetime())

      gtime.SetTimeZone("Asia/Tokyo")
      fmt.Println(gtime.Datetime())
      // May Output:
      // 2018-08-08 08:08:08
      // 2018-08-08 09:08:08
}

StrToTime

  • 说明:  时间字符串转成时间对象。
  • 格式:
func StrToTime(str string, format ...string) (*Time, error)
  • 示例: 时间字符串转成时间对象。
func ExampleStrToTime() {
      res, _ := gtime.StrToTime("2006-01-02T15:04:05-07:00", "Y-m-d H:i:s")
      fmt.Println(res)

      // May Output:
      // 2006-01-02 15:04:05
}

Add

  • 说明:  在当前时间对象上增加时间。
  • 格式:
func (t *Time) Add(d time.Duration) *Time
  • 示例: 在当前时间对象上增加时间。
func ExampleTime_Add() {
      gt := gtime.New("2018-08-08 08:08:08")
      gt1 := gt.Add(time.Duration(10) * time.Second)

      fmt.Println(gt1)

      // Output:
      // 2018-08-08 08:08:18
}

StartOfDay

  • 说明:  返回今天最开始的时间对象。类似的还有 StartOfHalf/StartOfHour/StartOfMonth/StartOfMinute/StartOfQuarter 等。
  • 格式:
func (t *Time) StartOfDay() *Time
  • 示例: 返回今天最开始的时间对象。
func ExampleTime_StartOfDay() {
      gt1 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.StartOfDay())

      // Output:
      // 2018-08-08 00:00:00
}

EndOfDay

  • 说明:  返回今天结束的时间对象。类似的还有 EndOfHalf/EndOfHour/EndOfMonth/EndOfMinute/EndOfQuarter 等。
  • 格式:
func (t *Time) EndOfDay() *Time
  • 示例: 返回今天结束的时间对象。
func ExampleTime_EndOfDay() {
      gt1 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.EndOfDay())

      // Output:
      // 2018-08-08 23:59:59
}

Month

  • 说明:  返回这个月处于全年的索引号。例如,1月对应的是1。
  • 格式:
func (t *Time) Month() int
  • 示例: 返回这个月处于全年的索引号。
func ExampleTime_Month() {
      gt := gtime.New("2018-08-08 08:08:08")
      t1 := gt.Month()

      fmt.Println(t1)

      // Output:
      // 8
}

Second

  • 说明:  返回当前分钟的秒数。例如,10:10:08 对应的秒数为8。
  • 格式:
func (t *Time) Second() int
  • 示例: 返回这个月处于全年的索引号。
func ExampleTime_Second() {
      gt := gtime.New("2018-08-08 08:08:08")
      t1 := gt.Second()

      fmt.Println(t1)

      // Output:
      // 8
}

IsZero

  • 说明:  判断时间是否等于 0001-01-01 00:00:00。注意不代表时间戳为0, 时间戳为0是 1970-01-01 08:00:00
  • 格式:
func (t *Time) IsZero() bool
  • 示例: 返回这个月处于全年的索引号。
func ExampleTime_IsZero() {
      gt := gtime.New("0-0-0")

      fmt.Println(gt.IsZero())

      // Output:
      // true
}

AddDate

  • 说明:  在当前时间对象上增加指定年月日。
  • 格式:
func (t *Time) AddDate(years int, months int, days int) *Time
  • 示例: 在当前时间对象上增加指定年月日。
func ExampleTime_AddDate() {
      var (
          year  = 1
          month = 2
          day   = 3
      )
      gt := gtime.New("2018-08-08 08:08:08")
      gt = gt.AddDate(year, month, day)

      fmt.Println(gt)

      // Output:
      // 2019-10-11 08:08:08
}

Equal

  • 说明:  判断两个时间对象是否相等。
  • 格式:
func (t *Time) Equal(u *Time) bool
  • 示例: 判断两个时间对象是否相等。
func ExampleTime_Equal() {
      gt1 := gtime.New("2018-08-08 08:08:08")
      gt2 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.Equal(gt2))

      // Output:
      // true
}

Before

  • 说明:  判断两个时间对象前后顺序。
  • 格式:
func (t *Time) Before(u *Time) bool
  • 示例: 判断两个时间对象前后顺序。
func ExampleTime_Before() {
      gt1 := gtime.New("2018-08-07 08:08:08")
      gt2 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.Before(gt2))

      // Output:
      // true
}

After

  • 说明:  判断两个时间对象前后顺序。
  • 格式:
func (t *Time) After(u *Time) bool
  • 示例: 判断两个时间对象前后顺序。
func ExampleTime_After() {
      gt1 := gtime.New("2018-08-07 08:08:08")
      gt2 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.After(gt2))

      // Output:
      // false
}

Layout

  • 说明:  格式化输出时间。
  • 格式:
func (t *Time) Layout(layout string) string
  • 示例: 格式化输出时间。
func ExampleTime_Layout() {
      gt1 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.Layout("2006-01-02"))

      // Output:
      // 2018-08-08
}

IsLeapYear

  • 说明:  是否闰年。
  • 格式:
func (t *Time) IsLeapYear() bool
  • 示例: 是否闰年。
func ExampleTime_IsLeapYear() {
      gt1 := gtime.New("2018-08-08 08:08:08")

      fmt.Println(gt1.IsLeapYear())

      // Output:
      // false
}

Date

  • 说明:  获取日期。
  • 格式:
func Date() string
  • 示例: 获取日期。
func ExampleDate() {
      fmt.Println(gtime.Date())

      // May Output:
      // 2006-01-02
}

Datetime

  • 说明:  获取日期时间。
  • 格式:
func Datetime() string
  • 示例: 获取日期。
func ExampleDatetime() {
      fmt.Println(gtime.Datetime())

      // May Output:
      // 2006-01-02 15:04:05
}

ISO8601

  • 说明:  以ISO8601的格式返回时间
  • 格式:
func ISO8601() string
  • 示例:
func ExampleISO8601() {
      fmt.Println(gtime.ISO8601())

      // May Output:
      // 2006-01-02T15:04:05-07:00
}

RFC822

  • 说明:  以RFC822的格式返回时间
  • 格式:
func RFC822() string
  • 示例:
func ExampleRFC822() {
      fmt.Println(gtime.RFC822())

      // May Output:
      // Mon, 02 Jan 06 15:04 MST
}

StrToTimeFormat

  • 说明:  StrToTimeFormat 根据传入的时间字符串以及格式返回时间对象
  • 格式:
func StrToTimeFormat(str string, format string) (*Time, error)
  • 示例:
func ExampleStrToTimeFormat() {
      res, _ := gtime.StrToTimeFormat("2006-01-02 15:04:05", "Y-m-d H:i:s")
      fmt.Println(res)

      // Output:
      // 2006-01-02 15:04:05
}

StrToTimeLayout

  • 说明:  StrToTimeLayout 根据传入的时间字符串以及格式返回时间对象
  • 格式:
func StrToTimeLayout(str string, layout string) (*Time, error)
  • 示例:
func ExampleStrToTimeLayout() {
      res, _ := gtime.StrToTimeLayout("2018-08-08", "2006-01-02")
      fmt.Println(res)

      // Output:
      // 2018-08-08 00:00:00
}

MarshalJSON

  • 说明:  MarshalJSON 重载 json.Marshal 中的方法。
  • 格式:
func (t *Time) MarshalJSON() ([]byte, error)
  • 示例:
func ExampleTime_MarshalJSON() {
      type Person struct {
          Name string        `json:"name"`
          Birthday *gtime.Time    `json:"birthday"`
      }
      p := new(Person)
      p.Name = "goframe"
      p.Birthday = gtime.New("2018-08-08 08:08:08")
      j, _ := json.Marshal(p)
      fmt.Println(string(j))

      // Output:
      // {"name":"xiaoming","birthday":"2018-08-08 08:08:08"}
}

UnmarshalJSON

  • 说明:  UnmarshalJSON 重载 json.Unmarshal 中的方法。
  • 格式:
func (t *Time) UnmarshalJSON() ([]byte, error)
  • 示例:
func ExampleTime_MarshalJSON() {
      type Person struct {
          Name string        `json:"name"`
          Birthday *gtime.Time    `json:"birthday"`
      }
      p := new(Person)
      p.Name = "goframe"
      p.Birthday = gtime.New("2018-08-08 08:08:08")
      j, _ := json.Marshal(p)
      fmt.Println(string(j))

      // Output:
      // {"name":"xiaoming","birthday":"2018-08-08 08:08:08"}
}

WeekOfYear

  • 说明:  WeekOfYear 返回当前周处于全年第几周,从1开始计算。类似的还有 DayOfYear/DaysInMonth
  • 格式:
func (t *Time) WeeksOfYear() int
  • 示例:
func ExampleTime_WeeksOfYear() {
      gt1 := gtime.New("2018-01-08 08:08:08")

      fmt.Println(gt1.WeeksOfYear())

      // Output:
      // 2
}D

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.