6050d11f27
- 创建基于 CloudWego Hertz 的 Go 微服务脚手架 - 集成 Nacos 服务注册/发现功能 - 添加 gRPC 客户端支持 - 实现环境变量配置管理 (.env.example) - 添加 HTTP 中间件 (Recovery, AccessLog, CORS) - 配置 Gitea CI/CD 构建部署流程 BREAKING CHANGE: 项目结构调整,从简单的 API 服务升级为完整的微服务架构
28 lines
462 B
Go
28 lines
462 B
Go
package middleware
|
|
|
|
import (
|
|
"apiServer_service/utils/logger"
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
)
|
|
|
|
func AccessLog() app.HandlerFunc {
|
|
return func(ctx context.Context, c *app.RequestContext) {
|
|
start := time.Now()
|
|
c.Next(ctx)
|
|
latency := time.Since(start)
|
|
|
|
logger.Info("HTTP",
|
|
fmt.Sprintf("%s %s %d %s",
|
|
string(c.Method()),
|
|
string(c.Request.URI().Path()),
|
|
c.Response.StatusCode(),
|
|
latency,
|
|
),
|
|
)
|
|
}
|
|
}
|