Skip to content

Commit e417759

Browse files
feat: add commas to the front page
1 parent d01d0bd commit e417759

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

models/view/home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Newsbox struct {
77

88
type HomeViewModel struct {
99
SharedViewModel
10-
TotalHours int
10+
TotalHours string
1111
TotalUsers int
1212
Newsbox *Newsbox
1313
}

routes/home.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,21 @@ func (h *HomeHandler) GetIndex(w http.ResponseWriter, r *http.Request) {
6060
}
6161

6262
func (h *HomeHandler) buildViewModel(r *http.Request, w http.ResponseWriter) *view.HomeViewModel {
63-
var totalHours int
63+
var totalHours string
6464
var totalUsers int
6565
var newsbox view.Newsbox
6666

67+
formatThousands := func(n int) string {
68+
s := strconv.Itoa(n)
69+
for i := len(s) - 3; i > 0; i -= 3 {
70+
s = s[:i] + "," + s[i:]
71+
}
72+
return s
73+
}
74+
6775
if kv, err := h.keyValueSrvc.GetString(conf.KeyLatestTotalTime); err == nil && kv != nil && kv.Value != "" {
6876
if d, err := time.ParseDuration(kv.Value); err == nil {
69-
totalHours = int(d.Hours())
77+
totalHours = formatThousands(int(d.Hours()))
7078
}
7179
}
7280

0 commit comments

Comments
 (0)