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

glog 是通用的高性能日志管理模块,实现了强大易用的日志管理功能,是 GoFrame 开发框架的核心组件之一。

基本介绍

使用方式:

import "github.com/gogf/gf/v2/os/glog"

接口文档:

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

简要说明:

  1. glog 模块固定日志文件名称格式为 *.log,即固定使用 .log 作为日志文件名后缀。
  2. glog 支持文件输出、日志级别、日志分类、调试管理、调用跟踪、链式操作、滚动切分等等丰富特性。
  3. 可以使用 glog.New 方法创建 glog.Logger 对象用于自定义日志打印,也可以并推荐使用 glog 默认提供的包方法来打印日志。
  4. 当使用包方法修改模块配置时,注意任何的 glog.Set* 设置方法都将会全局生效。
  5. 日志内容默认时间格式为 时间 [级别] 内容 换行,其中 时间 精确到毫秒级别,级别 为可选输出,内容 为调用端的参数输入,换行 为可选输出(部分方法自动为日志内容添加换行符号),日志内容示例:2018-10-10 12:00:01.568 [ERRO] 产生错误。
  6. Print*/Debug*/Info* 方法输出日志内容到标准输出(stdout),为防止日志的错乱,Notice*/Warning*/Error*/Critical*/Panic*/Fatal* 方法也是将日志内容输出到标准输出(stdout)。
  7. Panic* 方法在输出日志信息后会引发 panic 错误方法。
  8. Fatal* 方法在输出日志信息之后会停止进程运行,并返回进程状态码值为 1(正常程序退出状态码为 0)。

组件特性

glog 组件具有以下显著特性:

  • 使用简便,功能强大
  • 支持配置管理,使用统一的配置组件
  • 支持日志级别
  • 支持颜色打印
  • 支持链式操作
  • 支持指定输出日志文件或目录
  • 支持链路跟踪
  • 支持异步输出
  • 支持堆栈打印
  • 支持调试信息开关
  • 支持自定义 Writer 输出接口
  • 支持自定义日志 Handler 处理
  • 支持自定义日志 CtxKeys 键值
  • 支持 JSON 格式打印
  • 支持 Flags 特性
  • 支持 Rotate 滚动切分特性

单例对象

日志组件支持单例模式,使用 g.Log(单例名称) 获取不同的单例日志管理对象。提供单例对象的目的在于针对不同业务场景可以使用不同配置的日志管理对象。我们推荐使用 g.Log() 方法获取单例对象来进行日志操作,该方法内部会自动读取配置文件并初始化单例对象,该初始化操作仅会执行一次。

glog.Print 和 g.Log().Print 区别

  • glog 是日志组件的包名, g.Log() 是一个日志组件单例对象。
  • g.Log() 单例对象通过对象管理组件 g 包来维护,对象初始化时会自动读取日志配置,使用简便,大多数场景下推荐使用这种方式使用日志组件。
  • glog 通过独立组件的形式使用,默认情况下会直接输出日志到终端。也可以通过配置管理方法设置全局配置,或者通过 New 创建独立的日志对象使用。 :::tip 网友:为什么会有两种日志打印方式?我应该用哪种方式呢?

回答:

由于框架的每个组件都是 解耦化设计 的,框架是 可以作为独立的工具库使用 的。比如项目只需要使用日志组件,那么可以直接使用 glog 包的方法即可,不会引入其他的组件。但在项目工程化使用中,工具库的使用方式会较为繁琐,往往会涉及到配置和组件初始化(大部分场景会引起二次封装),因此框架也提供了一个 耦合包 叫做 g 包,这个包下面默认加载了一些常用的组件。 g.Log() 就是其中的日志组件,它会自动按照工程规范读取并初始化配置对象,快速初始化日志对象并实现单例管理,极大简化工程化下的日志使用。更多的介绍请参考: 对象管理 :::

相关文档

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.