http-metrics.go
· 330 B · Go
原始文件
import "github.com/felixge/httpsnoop"
handler := http.StripPrefix("/path/", http.FileServer(http.Dir("/tmp/files/")))
wrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
metrics := httpsnoop.CaptureMetrics(handler, w, r)
slog.Info(fmt.Sprintf("%v %v", r.Method, r.URL), "code", metrics.Code)
})
| 1 | import "github.com/felixge/httpsnoop" |
| 2 | |
| 3 | handler := http.StripPrefix("/path/", http.FileServer(http.Dir("/tmp/files/"))) |
| 4 | |
| 5 | wrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 6 | metrics := httpsnoop.CaptureMetrics(handler, w, r) |
| 7 | slog.Info(fmt.Sprintf("%v %v", r.Method, r.URL), "code", metrics.Code) |
| 8 | }) |