1. 调整CORS中间件挂载位置,重构CORS处理逻辑 2. 重写IP获取逻辑,增加私有网络IP信任校验 3. 优化日志中间件,移除/health接口单独日志逻辑 4. 改进API密钥未配置时的提示信息 5. 重构volcano TTS调用,新增voice参数支持 6. 优化请求体过大错误处理 7. 完善统计服务,修复环形缓冲区遍历逻辑,新增去重错误日志功能
29 lines
613 B
Go
29 lines
613 B
Go
package middleware
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type statusRecorder struct {
|
|
http.ResponseWriter
|
|
statusCode int
|
|
}
|
|
|
|
func (rec *statusRecorder) WriteHeader(code int) {
|
|
rec.statusCode = code
|
|
rec.ResponseWriter.WriteHeader(code)
|
|
}
|
|
|
|
func Logger(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
rec := &statusRecorder{ResponseWriter: w, statusCode: http.StatusOK}
|
|
next.ServeHTTP(rec, r)
|
|
duration := time.Since(start)
|
|
|
|
log.Printf("%s %s %s %d %v", r.Method, r.RequestURI, r.RemoteAddr, rec.statusCode, duration)
|
|
})
|
|
}
|