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

≈868 tokens on demand. Your agent reads this file only when SKILL.md points to it.

容器部署即使用 docker 化部署 golang 应用程序,这是在云服务时代最流行的部署方式,也是最推荐的部署方式。

在以下我们的示例中,统一使用 main 作为项目名称。

1. 编译程序

跨平台交叉编译是 golang 的特点之一,可以非常方便地编译出我们需要的目标服务器平台的版本,而且是静态编译,非常容易地解决了运行依赖问题。

使用以下指令可以静态编译 Linux 平台 amd64 架构的可执行文件:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main main.go

生成的 main 便是我们静态编译的,可部署于 Linux amd64 上的可执行文件。

2. 编译镜像

我们需要将该可执行文件 main 编译生成 docker 镜像,以便于分发及部署。 Golang 的运行环境推荐使用 alpine 基础系统镜像,编译出的容器镜像约为 20MB 左右。

一个参考的 Dockerfile 文件如下:

FROM loads/alpine:3.8

LABEL maintainer="john@goframe.org"

###############################################################################
#                                INSTALLATION
###############################################################################

# 设置固定的项目路径
ENV WORKDIR /app/main

# 添加应用可执行文件,并设置执行权限
ADD ./main   $WORKDIR/main
RUN chmod +x $WORKDIR/main

# 添加静态资源文件
ADD resource $WORKDIR/resource

###############################################################################
#                                   START
###############################################################################
WORKDIR $WORKDIR
CMD ./main

其中,我们的基础镜像使用了 loads/alpine:3.8,中国国内的用户推荐使用该基础镜像,基础镜像的 Dockerfile 地址: https://github.com/gqcn/dockerfiles ,仓库地址: https://hub.docker.com/u/loads

随后使用 docker build -t main . 指令编译生成名为 main 的 docker 镜像。

注意事项

需要注意的是,在某些项目的架构设计中, 静态文件 和 配置文件 可能不会随着镜像进行编译发布,而是分开进行管理和发布。

例如,使用 MVVM 模式的项目中(例如使用 vue 框架),往往是前后端非常独立的,因此在镜像中往往并不会包含 public 目录。而使用了 配置管理中心(例如使用 consul/ etcd/ zookeeper)的项目中,也往往并不需要 config 目录。

因此对于以上示例的 Dockerfile 的使用,仅作参考,根据实际情况请进行必要的调整。

3. 运行镜像

使用以下指令可直接运行刚才编译成的镜像:

docker run main

4. 镜像分发

容器的分发可以使用 docker 官方的平台: https://hub.docker.com/ ,国内也可以考虑使用阿里云: https://www.aliyun.com/product/acr 。

5. 容器编排

在企业级生产环境中, docker 容器往往需要结合 kubernetes 或者 docker swarm 容器编排工具一起使用。 容器编排涉及到的内容比较多,感兴趣的同学可以参考以下资料:

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.