@@ -10,6 +10,7 @@ import (
10
10
"crypto/sha256"
11
11
"encoding/hex"
12
12
"encoding/json"
13
+ "fmt"
13
14
"html"
14
15
"html/template"
15
16
"io"
@@ -182,6 +183,10 @@ func (ctx *Context) RedirectToFirst(location ...string) {
182
183
// HTML calls Context.HTML and converts template name to string.
183
184
func (ctx * Context ) HTML (status int , name base.TplName ) {
184
185
log .Debug ("Template: %s" , name )
186
+ var startTime = time .Now ()
187
+ ctx .Data ["TmplLoadTimes" ] = func () string {
188
+ return fmt .Sprint (time .Since (startTime ).Nanoseconds ()/ 1e6 ) + "ms"
189
+ }
185
190
if err := ctx .Render .HTML (ctx .Resp , status , string (name ), ctx .Data ); err != nil {
186
191
ctx .ServerError ("Render failed" , err )
187
192
}
@@ -190,6 +195,10 @@ func (ctx *Context) HTML(status int, name base.TplName) {
190
195
// HTMLString render content to a string but not http.ResponseWriter
191
196
func (ctx * Context ) HTMLString (name string , data interface {}) (string , error ) {
192
197
var buf strings.Builder
198
+ var startTime = time .Now ()
199
+ ctx .Data ["TmplLoadTimes" ] = func () string {
200
+ return fmt .Sprint (time .Since (startTime ).Nanoseconds ()/ 1e6 ) + "ms"
201
+ }
193
202
err := ctx .Render .HTML (& buf , 200 , string (name ), data )
194
203
return buf .String (), err
195
204
}
@@ -547,10 +556,7 @@ func Contexter() func(next http.Handler) http.Handler {
547
556
Data : map [string ]interface {}{
548
557
"CurrentURL" : setting .AppSubURL + req .URL .RequestURI (),
549
558
"PageStartTime" : startTime ,
550
- "TmplLoadTimes" : func () string {
551
- return time .Since (startTime ).String ()
552
- },
553
- "Link" : link ,
559
+ "Link" : link ,
554
560
},
555
561
}
556
562
0 commit comments