summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-01-10 00:05:26 +0100
committerAki <please@ignore.pl>2024-01-10 00:05:26 +0100
commit6fe3e5394e2e6736222ce85c7b5afbadffda5b82 (patch)
tree847b919c489ca277e576b2ba9b3b6d5eba6d94c1 /main.go
parent0f857271eac9995b90e16f58181d29a0bd6a47b6 (diff)
downloadrudone-6fe3e5394e2e6736222ce85c7b5afbadffda5b82.zip
rudone-6fe3e5394e2e6736222ce85c7b5afbadffda5b82.tar.gz
rudone-6fe3e5394e2e6736222ce85c7b5afbadffda5b82.tar.bz2
Added first visit date to the dashboard
Diffstat (limited to 'main.go')
-rw-r--r--main.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/main.go b/main.go
index 6b86223..011e8c4 100644
--- a/main.go
+++ b/main.go
@@ -3,6 +3,7 @@ package main
import (
"embed"
"encoding/json"
+ "fmt"
"html/template"
"log"
"net/http"
@@ -76,14 +77,18 @@ func handleEntryGet(w http.ResponseWriter, r *http.Request) {
}
type Stat struct {
- Title string
- Amount uint
+ Title string
+ Description string
}
type Home struct {
Stats []Stat
}
+func count(title string, amount int) Stat {
+ return Stat{title, fmt.Sprintf("%d visits", amount)}
+}
+
func handleHome(pathname string) func(http.ResponseWriter, *http.Request) {
t := template.Must(template.ParseFS(content, pathname))
return func(w http.ResponseWriter, r *http.Request) {
@@ -91,15 +96,19 @@ func handleHome(pathname string) func(http.ResponseWriter, *http.Request) {
now := time.Now().UTC()
last_day, err := EntriesSince(now.AddDate(0, 0, -1))
if err == nil {
- home.Stats = append(home.Stats, Stat{"Last 24 hours", uint(len(last_day))})
+ home.Stats = append(home.Stats, count("Last 24 hours", len(last_day)))
}
last_month, err := EntriesSince(now.AddDate(0, 0, -30))
if err == nil {
- home.Stats = append(home.Stats, Stat{"Last 30 days", uint(len(last_month))})
+ home.Stats = append(home.Stats, count("Last 30 days", len(last_month)))
+ }
+ total, err := CountEntries()
+ if err == nil {
+ home.Stats = append(home.Stats, count("Total", int(total)))
}
- total, err := CountEntries()
+ first, err := FirstEntry()
if err == nil {
- home.Stats = append(home.Stats, Stat{"Total", total})
+ home.Stats = append(home.Stats, Stat{"First visit", first.StartedAt.Format("_2 January 2006, 15:04")})
}
if len(home.Stats) < 1 {
http.Error(w, err.Error(), http.StatusInternalServerError)