diff options
| author | Fuwn <[email protected]> | 2021-07-14 23:06:33 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-07-14 23:06:33 +0000 |
| commit | 2ead92e075ecdceec9be7c852ad318299bc8d87e (patch) | |
| tree | 00c85a647830929ce8b3993bfb48e4b2154baff7 /template.go | |
| parent | feat(space): :gemini: (diff) | |
| download | space-2ead92e075ecdceec9be7c852ad318299bc8d87e.tar.xz space-2ead92e075ecdceec9be7c852ad318299bc8d87e.zip | |
feat(database): persistant hits
Diffstat (limited to 'template.go')
| -rw-r--r-- | template.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/template.go b/template.go index 69a7716..2e992d7 100644 --- a/template.go +++ b/template.go @@ -7,6 +7,7 @@ import ( "io" "text/template" + "github.com/fuwn/space/pkg/database" "github.com/pitr/gig" "github.com/spf13/viper" ) @@ -43,12 +44,11 @@ func (_ ErrorTemplate) HitsEnabled() bool { func (t *Template) Render(w io.Writer, name string, data interface{}, c gig.Context) error { // Check if the route is present in the hits tracker, if it isn't present, add // it, but either way: increment it. - // - // https://stackoverflow.com/a/2050570 - if _, ok := hitsTracker[c.Path()]; !ok { - hitsTracker[c.Path()] = 0 + hits := database.Get(c.Path()) + if hits == 0 { + database.Create(c.Path()) } - hitsTracker[c.Path()]++ + database.Increment(c.Path()) return t.Templates.ExecuteTemplate(w, name, data) } |