- 将踢脚线和勾缝线选项由复选框改为下拉选择,支持多种颜色选择 - 更新BuildCombinedFloorPrompt函数,支持传入颜色参数并显示对应中文名称 - 修改前端元素ID及相关逻辑,保持命名一致性和代码规范 - 新增material_source请求参数,支持图片来源选择 - 调整日志中跳过轮询请求,减少无用日志输出 - 修复部分函数命名和调用错误,提升代码健壮性
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"floorvisualizer/internal/logger"
|
|
)
|
|
|
|
type responseWriter struct {
|
|
http.ResponseWriter
|
|
statusCode int
|
|
wroteHeader bool
|
|
}
|
|
|
|
func (rw *responseWriter) WriteHeader(code int) {
|
|
if !rw.wroteHeader {
|
|
rw.statusCode = code
|
|
rw.wroteHeader = true
|
|
}
|
|
rw.ResponseWriter.WriteHeader(code)
|
|
}
|
|
|
|
func (rw *responseWriter) Write(b []byte) (int, error) {
|
|
if !rw.wroteHeader {
|
|
rw.statusCode = http.StatusOK
|
|
rw.wroteHeader = true
|
|
}
|
|
return rw.ResponseWriter.Write(b)
|
|
}
|
|
|
|
// Logging wraps an http.Handler with access logging, like Fiber's requestLogMiddleware.
|
|
// Format: METHOD /path 200 1.234ms
|
|
func Logging(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
rw := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK}
|
|
next.ServeHTTP(rw, r)
|
|
// Skip logging for polling endpoints to keep logs clean
|
|
if strings.HasPrefix(r.URL.Path, "/floor/status") {
|
|
return
|
|
}
|
|
logger.Info("%s %s %d %s", r.Method, r.URL.Path, rw.statusCode, time.Since(start))
|
|
})
|
|
}
|