6595e94677
经 deepseek/GLM/Claude 三轮对抗性评审 + 交叉核验 + 终审(见 last_report.md、cross_review_assessment.md),逐条回读源码核实并修复。 go build / vet / test -race ./... 全绿。 安全(P0): - JWT alg confusion:WithValidMethods 固定 HMAC + keyfunc 方法断言 - JWT 空密钥 / 不支持算法 fail-closed(ErrEmptySecret / ErrUnsupportedAlgorithm) - 上传大小实测封顶(enforceUploadSize),不信任客户端 file.Size - HTTP headers/cookies map 竞态(写锁+快照)+ SSRF 防护(opt-in dialer.Control) 并发/资源(主线A 闭合): - 包级可变全局一律 atomic.Pointer:DefaultRedis / DefaultStorage / DefaultManager / Validator / DefaultCache 等,消除裸指针数据竞争 - trace.Close 去 sync.Once(防 exporter 泄漏);app OnReady 失败走 Shutdown - ws.Hub.Stop stopOnce 防 double-close;cron 接入 App 生命周期(WithCron) - ratelimit failClosed atomic.Bool;Recover Written() 守卫 - cron checkAndRun 锁内收集锁外 spawn(wg.Add 在锁内防 Stop 竞态) 终审剩余项收口(H-A~M-H + L 系列): - 副本连接池 MaxOpenConns/2 截断修复(replicaMaxOpenConns) - JWT 黑名单 1s 超时 + 显式错误;ratelimit GetRedis 取一次复用 - GetPage 深分页上限;HashFile 流式;ReadFile 去 TOCTOU - config Clone() 深拷贝;cache 锁操作返 ErrRedisNotReady - compress 解压残留清理;正则预编译;EqualsIgnoreCase→EqualFold - 删 redisLimiters 死代码;CLI 输入校验 + 回滚 文档: - README/GUIDE/CHANGELOG 对齐当前 API(含破坏性变更迁移说明) - docs/README 索引修正;config 注释修正(RS256 已不支持) 破坏性变更详见 CHANGELOG.md [Unreleased]。项目处于研发初期、无下游用户。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
xlgo "github.com/EthanCodeCraft/xlgo-core"
|
|
)
|
|
|
|
func printUsage() {
|
|
fmt.Println(`xlgo - Go Web 框架脚手架工具
|
|
|
|
用法:
|
|
xlgo new <项目名> [--template <模板>] [--module <模块路径>] 创建新项目
|
|
xlgo make handler <名称> 创建处理器
|
|
xlgo make repository <名称> 创建仓库
|
|
xlgo make model <名称> 创建模型
|
|
xlgo make service <名称> 创建服务
|
|
xlgo version 显示版本号
|
|
|
|
模板 (xlgo new --template <名称>):
|
|
minimal 轻量 HTTP 服务,不依赖 MySQL/Redis(默认入门)
|
|
api 标准业务 API,含 MySQL/Redis/JWT 与 handler/model/repository/service 分层(默认)
|
|
fullstack 全组件,一键启用 MySQL/Redis/Storage/Swagger/AutoMigrate
|
|
|
|
示例:
|
|
xlgo new myapp
|
|
xlgo new myapp --template minimal
|
|
xlgo new myapp --template fullstack --module github.com/me/myapp
|
|
xlgo make handler user
|
|
xlgo make repository user`)
|
|
}
|
|
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
printUsage()
|
|
return
|
|
}
|
|
|
|
command := os.Args[1]
|
|
|
|
// P1 #21:命令执行失败时以非零码退出,便于 `xlgo new x && cd x` 等脚本/CI 正确中断。
|
|
switch command {
|
|
case "new":
|
|
if len(os.Args) < 3 {
|
|
fmt.Fprintln(os.Stderr, "用法: xlgo new <项目名>")
|
|
os.Exit(2)
|
|
}
|
|
if err := createProject(os.Args[2]); err != nil {
|
|
fmt.Fprintf(os.Stderr, "错误: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
case "make":
|
|
if len(os.Args) < 4 {
|
|
fmt.Fprintln(os.Stderr, "用法: xlgo make <类型> <名称>")
|
|
fmt.Fprintln(os.Stderr, "类型: handler, repository, model, service")
|
|
os.Exit(2)
|
|
}
|
|
if err := makeFile(os.Args[2], os.Args[3]); err != nil {
|
|
fmt.Fprintf(os.Stderr, "错误: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
case "version":
|
|
fmt.Printf("xlgo v%s\n", xlgo.Version)
|
|
|
|
default:
|
|
printUsage()
|
|
}
|
|
}
|