From 2d6c2f40a9a65dd456ef3f4795f3fd0838f06ff2 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Sun, 12 Jul 2020 18:46:45 +0200 Subject: [PATCH] feat: add more info in /open, add prettyDate helper, add anti-cache assets suffix --- pkg/sgtm/api.go | 2 +- pkg/sgtm/http_pages.go | 5 +++++ pkg/sgtm/service.go | 4 ++-- static/_layouts/base.tmpl.html | 8 ++++---- static/_layouts/home.tmpl.html | 1 - static/_layouts/open.tmpl.html | 1 + static/_layouts/post.tmpl.html | 2 +- static/_layouts/profile.tmpl.html | 5 +---- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/sgtm/api.go b/pkg/sgtm/api.go index e4e67b9..545c292 100644 --- a/pkg/sgtm/api.go +++ b/pkg/sgtm/api.go @@ -45,7 +45,7 @@ func (svc *Service) Ping(context.Context, *sgtmpb.Ping_Request) (*sgtmpb.Ping_Re func (svc *Service) Status(context.Context, *sgtmpb.Status_Request) (*sgtmpb.Status_Response, error) { hostname, _ := os.Hostname() return &sgtmpb.Status_Response{ - Uptime: int32(time.Since(svc.startedAt).Seconds()), + Uptime: int32(time.Since(svc.StartedAt).Seconds()), Hostname: hostname, }, nil } diff --git a/pkg/sgtm/http_pages.go b/pkg/sgtm/http_pages.go index f3e2a6e..608b8f6 100644 --- a/pkg/sgtm/http_pages.go +++ b/pkg/sgtm/http_pages.go @@ -414,6 +414,7 @@ func (svc *Service) newTemplateData(r *http.Request) (*templateData, error) { Opts: svc.opts.Filtered(), Lang: "en", // FIXME: dynamic Request: r, + Service: svc, } if svc.opts.DevMode { data.Title += " (dev)" @@ -459,6 +460,9 @@ func loadTemplate(box *packr.Box, filepath string) *template.Template { funcmap["prettyDuration"] = func(input time.Duration) string { return durafmt.Parse(input).LimitFirstN(2).String() } + funcmap["prettyDate"] = func(input time.Time) string { + return input.Format("2006-01-02 15:04") + } tmpl, err := template.New("tmpl").Funcs(funcmap).Parse(allInOne) if err != nil { panic(err) @@ -478,6 +482,7 @@ type templateData struct { Lang string User *sgtmpb.User Error string + Service *Service `json:"-"` Request *http.Request `json:"-"` // specific diff --git a/pkg/sgtm/service.go b/pkg/sgtm/service.go index 55acdfc..102ccd5 100644 --- a/pkg/sgtm/service.go +++ b/pkg/sgtm/service.go @@ -17,7 +17,7 @@ type Service struct { opts Opts ctx context.Context cancel func() - startedAt time.Time + StartedAt time.Time /// drivers @@ -37,7 +37,7 @@ func New(db *gorm.DB, opts Opts) (Service, error) { opts: opts, ctx: ctx, cancel: cancel, - startedAt: time.Now(), + StartedAt: time.Now(), } svc.logger.Info("service initialized", zap.Bool("dev-mode", opts.DevMode)) return svc, nil diff --git a/static/_layouts/base.tmpl.html b/static/_layouts/base.tmpl.html index bc9d335..37360d2 100644 --- a/static/_layouts/base.tmpl.html +++ b/static/_layouts/base.tmpl.html @@ -4,8 +4,8 @@
- - + +