Skip to content

Commit ae2ca2b

Browse files
committed
add Link column to home.html
1 parent 41e9dc9 commit ae2ca2b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: golink.go

+12
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ var (
264264

265265
type visitData struct {
266266
Short string
267+
Long string
267268
NumClicks int
268269
}
269270

@@ -404,10 +405,21 @@ func serveHandler() http.Handler {
404405
func serveHome(w http.ResponseWriter, r *http.Request, short string) {
405406
var clicks []visitData
406407

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+
407418
stats.mu.Lock()
408419
for short, numClicks := range stats.clicks {
409420
clicks = append(clicks, visitData{
410421
Short: short,
422+
Long: linkMap[short],
411423
NumClicks: numClicks,
412424
})
413425
}

Diff for: tmpl/home.html

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ <h2 class="text-xl font-bold pt-6 pb-2">Popular Links</h2>
2323
<tr>
2424
<th class="p-2">Link</th>
2525
<th class="p-2">Clicks</th>
26+
<th class="p-2">URL</th>
2627
</tr>
2728
</thead>
2829
<tbody>
@@ -35,6 +36,7 @@ <h2 class="text-xl font-bold pt-6 pb-2">Popular Links</h2>
3536
</a>
3637
</td>
3738
<td class="p-2">{{.NumClicks}}</td>
39+
<td class="p-2">{{.Long}}</td>
3840
</tr>
3941
{{end}}
4042
</tbody>

0 commit comments

Comments
 (0)