Skip to content

Commit 551f90a

Browse files
authored
short: sort the stats page (#5)
1 parent 703974f commit 551f90a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

short.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"log"
1616
"net"
1717
"net/http"
18+
"sort"
1819
"strings"
1920
"time"
2021

@@ -202,7 +203,7 @@ func (s *server) stats(ctx context.Context, w http.ResponseWriter) (retErr error
202203
if retErr != nil {
203204
return
204205
}
205-
fmt.Println(conf.GoogleAnalytics)
206+
206207
ars := arecords{
207208
Title: conf.Title,
208209
Host: conf.Host,
@@ -222,6 +223,13 @@ func (s *server) stats(ctx context.Context, w http.ResponseWriter) (retErr error
222223
}
223224
}
224225

226+
sort.Slice(ars.Records, func(i, j int) bool {
227+
if ars.Records[i].PV > ars.Records[j].PV {
228+
return true
229+
}
230+
return ars.Records[i].UV > ars.Records[j].UV
231+
})
232+
225233
var buf bytes.Buffer
226234
retErr = statsTmpl.Execute(&buf, ars)
227235
if retErr != nil {

0 commit comments

Comments
 (0)