Include time taken to render in footer

This commit is contained in:
Tom Wiesing 2023-11-10 20:34:20 +01:00
parent 7fefb689c7
commit 733aa237d1
No known key found for this signature in database
4 changed files with 17 additions and 1 deletions

View file

@ -37,10 +37,21 @@ type RuntimeFlags struct {
RequestURI string // request uri of the current page
Menu []component.MenuItem // menu at the top of the page
StartedAt time.Time // time the request started to generate
GeneratedAt time.Time // time the underlying data returned
CSRF template.HTML // csrf data (if any)
}
// Returns how long this request took to render
func (rf RuntimeFlags) Took() time.Duration {
return time.Since(rf.StartedAt)
}
func (rf RuntimeFlags) TookHTML() template.HTML {
took := rf.Took()
return template.HTML(fmt.Sprintf("<time datetime=\"P%.3f\">%s</time>", took.Seconds(), took))
}
var runtimeFlagsName = reflectx.TypeFor[RuntimeFlags]().Name()
// Clone clones this flags