2025-03-18 07:43:46 +08:00

21 lines
358 B
Go

package middleware
import (
"log"
"net/http"
"time"
)
// 审计日志中间件
func AuditLog(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
next.ServeHTTP(w, r)
log.Printf(
"Method=%s Path=%s Duration=%s",
r.Method,
r.URL.Path,
time.Since(start),
)
})
}