From 1c704ffca563773b0ca994fecbe3f4d3bd9ed63e Mon Sep 17 00:00:00 2001 From: shaftoes Date: Thu, 9 May 2024 12:03:45 -0400 Subject: [PATCH 1/2] add Link column to home.html Signed-off-by: shaftoes --- golink.go | 12 ++++++++++++ tmpl/home.html | 2 ++ 2 files changed, 14 insertions(+) diff --git a/golink.go b/golink.go index 298eb86..3371822 100644 --- a/golink.go +++ b/golink.go @@ -264,6 +264,7 @@ var ( type visitData struct { Short string + Long string NumClicks int } @@ -404,10 +405,21 @@ func serveHandler() http.Handler { func serveHome(w http.ResponseWriter, r *http.Request, short string) { var clicks []visitData + linkMap := map[string]string{} + links, err := db.LoadAll() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + for _, link := range links { + linkMap[link.Short] = link.Long + } + stats.mu.Lock() for short, numClicks := range stats.clicks { clicks = append(clicks, visitData{ Short: short, + Long: linkMap[short], NumClicks: numClicks, }) } diff --git a/tmpl/home.html b/tmpl/home.html index 64e2267..a28e0a8 100644 --- a/tmpl/home.html +++ b/tmpl/home.html @@ -23,6 +23,7 @@

Popular Links

Link Clicks + URL @@ -35,6 +36,7 @@

Popular Links

{{.NumClicks}} + {{.Long}} {{end}} From 877c565c250fabc04480896ba05211da71285c59 Mon Sep 17 00:00:00 2001 From: shaftoes Date: Thu, 9 May 2024 12:07:43 -0400 Subject: [PATCH 2/2] turn url into full link Signed-off-by: shaftoes --- tmpl/home.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmpl/home.html b/tmpl/home.html index a28e0a8..46e6123 100644 --- a/tmpl/home.html +++ b/tmpl/home.html @@ -36,7 +36,7 @@

Popular Links

{{.NumClicks}} - {{.Long}} + {{.Long}} {{end}}