1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 10:51:30 +00:00

Merge pull request #3405 from coldnight/feature-add-elapsed-in-response

Add .Elapsed in context.ResponseWriter for monitor purpose
This commit is contained in:
astaxie 2018-11-20 15:39:13 +08:00 committed by GitHub
commit a17eb54515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -201,6 +201,7 @@ type Response struct {
http.ResponseWriter http.ResponseWriter
Started bool Started bool
Status int Status int
Elapsed time.Duration
} }
func (r *Response) reset(rw http.ResponseWriter) { func (r *Response) reset(rw http.ResponseWriter) {

View File

@ -890,8 +890,9 @@ Admin:
logAccess(context, &startTime, statusCode) logAccess(context, &startTime, statusCode)
if BConfig.Listen.EnableAdmin {
timeDur := time.Since(startTime) timeDur := time.Since(startTime)
context.ResponseWriter.Elapsed = timeDur
if BConfig.Listen.EnableAdmin {
pattern := "" pattern := ""
if routerInfo != nil { if routerInfo != nil {
pattern = routerInfo.pattern pattern = routerInfo.pattern
@ -908,7 +909,6 @@ Admin:
if BConfig.RunMode == DEV && !BConfig.Log.AccessLogs { if BConfig.RunMode == DEV && !BConfig.Log.AccessLogs {
var devInfo string var devInfo string
timeDur := time.Since(startTime)
iswin := (runtime.GOOS == "windows") iswin := (runtime.GOOS == "windows")
statusColor := logs.ColorByStatus(iswin, statusCode) statusColor := logs.ColorByStatus(iswin, statusCode)
methodColor := logs.ColorByMethod(iswin, r.Method) methodColor := logs.ColorByMethod(iswin, r.Method)