Include time taken to render in footer
This commit is contained in:
parent
7fefb689c7
commit
733aa237d1
4 changed files with 17 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||||
"github.com/tkw1536/pkglib/contextx"
|
"github.com/tkw1536/pkglib/contextx"
|
||||||
"github.com/tkw1536/pkglib/httpx"
|
"github.com/tkw1536/pkglib/httpx"
|
||||||
|
"github.com/tkw1536/pkglib/httpx/timewrap"
|
||||||
"github.com/tkw1536/pkglib/mux"
|
"github.com/tkw1536/pkglib/mux"
|
||||||
|
|
||||||
"github.com/gorilla/csrf"
|
"github.com/gorilla/csrf"
|
||||||
|
|
@ -113,6 +114,8 @@ func (server *Server) Server(ctx context.Context, progress io.Writer) (public ht
|
||||||
public = WithCSP(public, models.ContentSecurityPolicyDistilery)
|
public = WithCSP(public, models.ContentSecurityPolicyDistilery)
|
||||||
internal = WithCSP(internal, models.ContentSecurityPolicyNothing)
|
internal = WithCSP(internal, models.ContentSecurityPolicyNothing)
|
||||||
|
|
||||||
|
public = timewrap.Wrap(public)
|
||||||
|
|
||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/gorilla/csrf"
|
"github.com/gorilla/csrf"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/tkw1536/pkglib/httpx"
|
"github.com/tkw1536/pkglib/httpx"
|
||||||
|
"github.com/tkw1536/pkglib/httpx/timewrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed "src/base.html"
|
//go:embed "src/base.html"
|
||||||
|
|
@ -44,6 +45,7 @@ func (tpl *Template[C]) context(r *http.Request, funcs ...FlagFunc) (ctx *tConte
|
||||||
// setup the basic properties
|
// setup the basic properties
|
||||||
ctx.ctx = r.Context()
|
ctx.ctx = r.Context()
|
||||||
ctx.Runtime.RequestURI = r.URL.RequestURI()
|
ctx.Runtime.RequestURI = r.URL.RequestURI()
|
||||||
|
ctx.Runtime.StartedAt = timewrap.Start(r).UTC()
|
||||||
ctx.Runtime.GeneratedAt = time.Now().UTC()
|
ctx.Runtime.GeneratedAt = time.Now().UTC()
|
||||||
ctx.Runtime.CSRF = csrf.TemplateField(r)
|
ctx.Runtime.CSRF = csrf.TemplateField(r)
|
||||||
ctx.Runtime.Menu = tpl.templating.buildMenu(r)
|
ctx.Runtime.Menu = tpl.templating.buildMenu(r)
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,21 @@ type RuntimeFlags struct {
|
||||||
|
|
||||||
RequestURI string // request uri of the current page
|
RequestURI string // request uri of the current page
|
||||||
Menu []component.MenuItem // menu at the top of the 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
|
GeneratedAt time.Time // time the underlying data returned
|
||||||
CSRF template.HTML // csrf data (if any)
|
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()
|
var runtimeFlagsName = reflectx.TypeFor[RuntimeFlags]().Name()
|
||||||
|
|
||||||
// Clone clones this flags
|
// Clone clones this flags
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
<p>
|
<p>
|
||||||
Generated <time format="{{ .GeneratedAt.Format "2006-01-02T15:04:05Z" }}">{{ .GeneratedAt.Format "2006-01-02T15:04:05Z07:00" }}</time> by <a href="https://github.com/FAU-CDI/wisski-distillery" target="_blank" rel="noopener noreferer">WissKI Distillery</a>. This site might use cookies for essential purposes, see also <a href="/legal/">Legal Notices</a>.
|
Generated at <time datetime="{{ .GeneratedAt.Format "2006-01-02T15:04:05Z" }}">{{ .GeneratedAt.Format "2006-01-02T15:04:05Z07:00" }}</time> in {{ .TookHTML }} by <a href="https://github.com/FAU-CDI/wisski-distillery" target="_blank" rel="noopener noreferer">WissKI Distillery</a>. This site might use cookies for essential purposes, see also <a href="/legal/">Legal Notices</a>.
|
||||||
</p>
|
</p>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue