.
,-. ,-. . . ,-. ,-. ,-. ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . .
`-. | | | | | | |-' | | | | | | | | | | | | | | | | |
`-' `-' `-^ ' `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-|
/|
`-'
Fuwn / space
No description
git clone https://source.community/Fuwn/space.git
/template.go (main)
Blob
View raw contents of /template.go (main)
โโโโโฎ
1โ // Copyright (C) 2021-2021 Fuwn
2โ // SPDX-License-Identifier: GPL-3.0-only
3โ
4โ package main
5โ
6โ import (
7โ "io"
8โ "text/template"
9โ
10โ "github.com/fuwn/space/pkg/database"
11โ "github.com/pitr/gig"
12โ "github.com/spf13/viper"
13โ )
14โ
15โ type Template struct {
16โ Templates *template.Template
17โ }
18โ
19โ type IndexTemplate struct {
20โ Content string
21โ Quote string
22โ Hits int
23โ // SystemInfo string
24โ Copyright string
25โ }
26โ type ErrorTemplate struct {
27โ Error string
28โ Content string
29โ Quote string
30โ Hits int
31โ Copyright string
32โ }
33โ
34โ // Lazy...
35โ func isHitsEnabled() bool {
36โ return viper.GetBool("space.hits")
37โ }
38โ func (_ IndexTemplate) HitsEnabled() bool {
39โ return isHitsEnabled()
40โ }
41โ func (_ ErrorTemplate) HitsEnabled() bool {
42โ return isHitsEnabled()
43โ }
44โ
45โ func (t *Template) Render(w io.Writer, name string, data interface{}, c gig.Context) error {
46โ // Check if the route is present in the hits tracker, if it isn't present, add
47โ // it, but either way: increment it.
48โ hits := database.Get(c.Path())
49โ if hits == 0 {
50โ database.Create(c.Path())
51โ }
52โ database.Increment(c.Path())
53โ
54โ return t.Templates.ExecuteTemplate(w, name, data)
55โ }
โโโโโฏ
ยท ยท ยท
ยฉ 2026 source.community