feat: 添加应用骨架,配置化 zap 日志贯穿全链路
- cmd/server/main.go: 使用 logger.NewLogger(cfg.Log) 替代 zap.NewProduction() - internal/app: 依赖注入组装 DB/Slurm/Service/Handler,传递 logger - internal/middleware: RequestLogger 请求日志中间件 - internal/server: 统一响应格式和路由注册 - go.mod: module 更名为 gcy_hpc_server,添加 gin/zap/lumberjack/gorm 依赖 - 日志初始化失败时 fail fast (os.Exit(1)) - GormLevel 从配置传递到 NewGormDB,支持 YAML 独立配置 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
25
internal/app/app_test.go
Normal file
25
internal/app/app_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gcy_hpc_server/internal/config"
|
||||
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
func TestNewApp_InvalidDB(t *testing.T) {
|
||||
cfg := &config.Config{
|
||||
ServerPort: "8080",
|
||||
MySQLDSN: "invalid:dsn@tcp(localhost:99999)/nonexistent?parseTime=true",
|
||||
SlurmAPIURL: "http://localhost:6820",
|
||||
SlurmUserName: "root",
|
||||
SlurmJWTKeyPath: "/nonexistent/jwt.key",
|
||||
}
|
||||
logger := zaptest.NewLogger(t)
|
||||
|
||||
_, err := NewApp(cfg, logger)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid DSN, got nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user