File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,7 @@ var (
264
264
265
265
type visitData struct {
266
266
Short string
267
+ Long string
267
268
NumClicks int
268
269
}
269
270
@@ -404,10 +405,21 @@ func serveHandler() http.Handler {
404
405
func serveHome (w http.ResponseWriter , r * http.Request , short string ) {
405
406
var clicks []visitData
406
407
408
+ linkMap := map [string ]string {}
409
+ links , err := db .LoadAll ()
410
+ if err != nil {
411
+ http .Error (w , err .Error (), http .StatusInternalServerError )
412
+ return
413
+ }
414
+ for _ , link := range links {
415
+ linkMap [link .Short ] = link .Long
416
+ }
417
+
407
418
stats .mu .Lock ()
408
419
for short , numClicks := range stats .clicks {
409
420
clicks = append (clicks , visitData {
410
421
Short : short ,
422
+ Long : linkMap [short ],
411
423
NumClicks : numClicks ,
412
424
})
413
425
}
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ <h2 class="text-xl font-bold pt-6 pb-2">Popular Links</h2>
23
23
< tr >
24
24
< th class ="p-2 "> Link</ th >
25
25
< th class ="p-2 "> Clicks</ th >
26
+ < th class ="p-2 "> URL</ th >
26
27
</ tr >
27
28
</ thead >
28
29
< tbody >
@@ -35,6 +36,7 @@ <h2 class="text-xl font-bold pt-6 pb-2">Popular Links</h2>
35
36
</ a >
36
37
</ td >
37
38
< td class ="p-2 "> {{.NumClicks}}</ td >
39
+ < td class ="p-2 "> {{.Long}}</ td >
38
40
</ tr >
39
41
{{end}}
40
42
</ tbody >
You can’t perform that action at this time.
0 commit comments