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.

examplesregistryetcdREADME.ZH.MD

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

注册中心 - Etcd 集成

简介

本示例演示了如何在 GoFrame 应用程序中集成 Etcd 服务注册中心。主要展示:

  • 使用 Etcd 注册服务
  • 使用 Etcd 发现服务
  • 实现服务健康检查
  • 构建分布式系统

目录结构

.
├── grpc/                # gRPC服务示例
│   ├── client/          # gRPC客户端实现
│   ├── controller/      # gRPC服务控制器
│   ├── protobuf/        # Protocol buffer定义
│   └── server/          # gRPC服务器实现
│       ├── main.go      # 服务器启动代码
│       └── config.yaml  # 服务器配置
├── http/                # HTTP服务示例
│   ├── client/          # HTTP客户端实现
│   └── server/          # HTTP服务器实现
├── go.mod               # Go模块文件
└── go.sum               # Go模块校验和

功能特性

本示例展示了以下功能:

  1. 服务注册

    • 自动服务注册
    • 基于TTL的健康检查
    • 元数据管理
    • 租约管理
  2. 服务发现

    • 动态服务发现
    • 负载均衡
    • 故障转移支持
    • Watch机制监控
  3. 协议支持

    • HTTP 服务注册与发现
    • gRPC 服务注册与发现

环境要求

  • Go 1.22 或更高版本
  • Docker (用于运行 Etcd)
  • Etcd 3.4+

使用说明

  1. 启动 Etcd 服务:

    docker run -d --name etcd -p 2379:2379 -e ALLOW_NONE_AUTHENTICATION=yes bitnami/etcd:3.4.24
  2. HTTP 服务示例:

    # 启动HTTP服务器
    cd http/server
    go run server.go
    
    # 运行HTTP客户端
    cd http/client
    go run client.go
  3. gRPC 服务示例:

    # 启动gRPC服务器
    cd grpc/server
    go run server.go
    
    # 运行gRPC客户端
    cd grpc/client
    go run client.go

实现说明

  1. HTTP 服务实现

    • 服务器使用 g.Server 创建 HTTP 服务
    • 通过 gsvc.SetRegistry 设置 Etcd 注册中心
    • 客户端使用 g.Client() 自动发现并访问服务
    • 支持自动的健康检查和租约续期
  2. gRPC 服务实现

    • 服务器使用 grpc.Server 创建 gRPC 服务
    • 通过 gsvc.SetRegistry 设置 Etcd 注册中心
    • 客户端使用 grpc.Client 自动发现并访问服务
    • 支持自动的健康检查和租约续期

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.