最后活跃于 1 month ago

mila 修订了这个 Gist 2 years ago. 转到此修订

没有任何变更

mila 修订了这个 Gist 2 years ago. 转到此修订

1 file changed, 2 insertions

gistfile1.txt 重命名为 http-metrics.go

@@ -1,5 +1,7 @@
1 1 import "github.com/felixge/httpsnoop"
2 2
3 + handler := http.StripPrefix("/path/", http.FileServer(http.Dir("/tmp/files/")))
4 +
3 5 wrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4 6 metrics := httpsnoop.CaptureMetrics(handler, w, r)
5 7 slog.Info(fmt.Sprintf("%v %v", r.Method, r.URL), "code", metrics.Code)

mila 修订了这个 Gist 2 years ago. 转到此修订

1 file changed, 6 insertions

gistfile1.txt(文件已创建)

@@ -0,0 +1,6 @@
1 + import "github.com/felixge/httpsnoop"
2 +
3 + wrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4 + metrics := httpsnoop.CaptureMetrics(handler, w, r)
5 + slog.Info(fmt.Sprintf("%v %v", r.Method, r.URL), "code", metrics.Code)
6 + })
上一页 下一页