Browse Source

Let's parse links before saving

Piotr Czajkowski 3 years ago
parent
commit
bea9bd06e2
1 changed files with 7 additions and 0 deletions
  1. 7 0
      storage.go

+ 7 - 0
storage.go

@@ -4,6 +4,7 @@ import (
 	"bufio"
 	"fmt"
 	"log"
+	"net/url"
 	"os"
 	"strings"
 	"sync"
@@ -50,6 +51,12 @@ func readLinks(path string) {
 }
 
 func addLink(link string, toSave chan<- string) string {
+	u, err := url.Parse(link)
+	if err != nil {
+		log.Printf("Error parsing link: %s", err)
+	}
+	link = u.String()
+
 	linkID := getHash(link)
 
 	existingLink, loaded := links.LoadOrStore(linkID, link)