From b021686521e84ac5a37710ec81a48908bf3fd557 Mon Sep 17 00:00:00 2001 From: wanghui Date: Mon, 19 Nov 2018 16:38:14 +0800 Subject: [PATCH] Add .Elapsed in context.ResponseWriter for monitor purpose With this commit we can record per requests's elapsed time, so we can easy to monitor that by use a filter. --- context/context.go | 3 ++- router.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/context/context.go b/context/context.go index 452834e5..bbd58299 100644 --- a/context/context.go +++ b/context/context.go @@ -201,6 +201,7 @@ type Response struct { http.ResponseWriter Started bool Status int + Elapsed time.Duration } func (r *Response) reset(rw http.ResponseWriter) { @@ -259,4 +260,4 @@ func (r *Response) Pusher() (pusher http.Pusher) { return pusher } return nil -} \ No newline at end of file +} diff --git a/router.go b/router.go index 4ecac6bc..5c78b42c 100644 --- a/router.go +++ b/router.go @@ -890,8 +890,9 @@ Admin: logAccess(context, &startTime, statusCode) + timeDur := time.Since(startTime) + context.ResponseWriter.Elapsed = timeDur if BConfig.Listen.EnableAdmin { - timeDur := time.Since(startTime) pattern := "" if routerInfo != nil { pattern = routerInfo.pattern @@ -908,7 +909,6 @@ Admin: if BConfig.RunMode == DEV && !BConfig.Log.AccessLogs { var devInfo string - timeDur := time.Since(startTime) iswin := (runtime.GOOS == "windows") statusColor := logs.ColorByStatus(iswin, statusCode) methodColor := logs.ColorByMethod(iswin, r.Method)