GoWind 开源生态GoWind 开源生态
首页
框架
GoWind Admin
GoWind CMS
GoWind IM
GoWind UBA
GoWind IoT
GoWind Toolkit
GoWind Quant
GitHub
首页
框架
GoWind Admin
GoWind CMS
GoWind IM
GoWind UBA
GoWind IoT
GoWind Toolkit
GoWind Quant
GitHub
  • 介绍

    • GoWind 框架
    • 框架整体架构
  • go-wind 核心

    • go-wind 核心框架
    • App 生命周期管理
    • Context 传播
    • Transport 抽象
    • Log 门面接口
  • go-wind-plugins 插件

    • go-wind-plugins 插件总览
    • 插件配置系统
    • 插件注册机制(SPI)
    • 日志适配插件
    • 传输协议插件
    • 消息中间件插件
    • 编码解码插件
    • 安全与认证插件
    • 链路追踪插件
    • 缓存插件
    • 对象存储插件(OSS)
    • 限流插件
    • 指标监控插件
    • AI 插件
    • 工作流插件
    • 数据库与缓存插件
    • Bootstrap 集成与网关插件
    • 压缩与序列化插件
    • 模板渲染与验证插件
  • go-wind-bootstrap 启动器

    • go-wind-bootstrap 声明式启动器
    • Bootstrap 配置系统
    • Bootstrap SPI 机制
    • 声明式中间件编排
    • Bootstrap CLI 工具
    • Bootstrap 实战示例
  • 教程

    • 快速入门教程
    • 自定义插件开发教程
    • 多协议同时监听教程
    • 框架迁移指南

Bootstrap CLI 工具

go-wind-bootstrap 提供命令行工具,用于项目初始化、代码生成和开发辅助。

一、安装

go install github.com/tx7do/go-wind-bootstrap/cmd/wind@latest

二、命令一览

$ wind --help
GoWind Bootstrap CLI

Usage:
  wind [command]

Available Commands:
  new         创建新项目
  run         启动服务(支持热重载)
  gen         代码生成
  config      检查/验证配置
  version     版本信息

Flags:
  -h, --help   help for wind

三、创建新项目

# 基础项目
wind new my-service

# 指定插件组合
wind new my-service \
  --transport http,grpc \
  --database mysql \
  --cache redis \
  --broker kafka \
  --log zap \
  --tracer jaeger

# 指定模块路径
wind new my-service --module github.com/myorg/my-service

生成的项目结构

my-service/
├── cmd/
│   └── server/
│       └── main.go              # 入口(含 blank import)
├── configs/
│   └── config.yaml              # 配置模板
├── ent/
│   └── schema/                  # Ent 实体定义
│       └── user.go
├── api/
│   └── v1/
│       └── user.proto           # Protobuf API
├── internal/
│   ├── service/
│   │   └── user_service.go      # 业务逻辑
│   ├── repo/
│   │   └── user_repo.go         # 数据访问
│   └── router/
│       └── router.go            # 路由配置
├── Makefile
├── Dockerfile
├── go.mod
└── go.sum

生成的 main.go

package main

import (
    _ "github.com/tx7do/go-wind-plugins/transport/http"
    _ "github.com/tx7do/go-wind-plugins/transport/grpc"
    _ "github.com/tx7do/go-wind-plugins/log/zap"
    _ "github.com/tx7do/go-wind-plugins/database/mysql"
    _ "github.com/tx7do/go-wind-plugins/cache/redis"
    _ "github.com/tx7do/go-wind-plugins/broker/kafka"
    _ "github.com/tx7do/go-wind-plugins/tracer/jaeger"

    "github.com/tx7do/go-wind-bootstrap"
    _ "my-service/internal/router"
)

func main() {
    app := bootstrap.New("configs/config.yaml")
    app.Run()
}

四、开发热重载

# 启动并监听文件变更
wind run

# 等效于 air / realize 等热重载工具
# 修改 .go 文件自动重新编译和重启
# .wind.yaml(热重载配置)
run:
  watch:
    - "*.go"
    - "configs/*.yaml"
    - "ent/schema/*.go"
  exclude:
    - "vendor"
    - ".git"
    - "tmp"
  delay: 500ms         # 文件变更后等待时间
  build_args:
    - -race
    - -tags=development

五、代码生成

5.1 Ent 代码生成

# 从 schema 生成 Ent 代码
wind gen ent

# 等效于 go generate ./ent

5.2 Protobuf 代码生成

# 从 .proto 生成 Go/TS/OpenAPI 代码
wind gen proto

# 指定输出目录
wind gen proto --out ./api/gen

5.3 CRUD 脚手架

# 根据实体定义生成 CRUD 代码
wind gen crud --entity User

# 生成内容:
# - ent/schema/user.go(如有缺失)
# - internal/repo/user_repo.go
# - internal/service/user_service.go
# - api/v1/user.proto

六、配置检查

# 验证配置文件格式
wind config validate configs/config.yaml

# 查看最终合并后的配置(含环境变量替换)
wind config render configs/config.yaml

# 检查配置项是否匹配已注册的插件
wind config check

输出示例

$ wind config validate configs/config.yaml

✓ server.http.addr = ":8080"
✓ log.zap.level = "info"
✓ database.default.dsn = "user:***@tcp(localhost:3306)/db"
✗ cache.redis: unknown plugin "redis" (did you forget to import?)
✗ auth.jwt.key = "" (empty, must set JWT_SECRET)

2 errors, 0 warnings

七、版本管理

# 当前版本
wind version

# GoWind 生态版本
wind version --all

# 输出:
# wind CLI:        v1.2.3
# go-wind:         v1.5.0
# go-wind-plugins:  v1.8.2
# go-wind-bootstrap: v1.3.1

八、Makefile 集成

生成的项目自带 Makefile:

.PHONY: build run test gen

build:
	go build -o bin/server ./cmd/server

run:
	wind run

dev:
	go run ./cmd/server --config configs/config.yaml

test:
	go test ./... -v -cover

gen:
	wind gen ent
	wind gen proto

docker:
	docker build -t my-service .

clean:
	rm -rf bin/ tmp/

相关文档

  • Bootstrap 介绍
  • Bootstrap 配置系统
  • 快速入门教程
Edit this page
Last Updated:: 6/21/26, 9:28 PM
Contributors: Bobo
Prev
声明式中间件编排
Next
Bootstrap 实战示例