summaryrefslogtreecommitdiff
path: root/crawler/utility.go
diff options
context:
space:
mode:
Diffstat (limited to 'crawler/utility.go')
-rw-r--r--crawler/utility.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/crawler/utility.go b/crawler/utility.go
index 5b91c51..d282dbd 100644
--- a/crawler/utility.go
+++ b/crawler/utility.go
@@ -3,9 +3,11 @@ package main
import (
"errors"
"math"
+ "math/rand"
"regexp"
"strconv"
"strings"
+ "time"
"github.com/gocolly/colly"
)
@@ -370,3 +372,17 @@ func RoundToEven(x float64) float64 {
}
return t
}
+
+/*
+ * Returns random string with len n, used for short urls
+ */
+func getRandomString(n int) string {
+ var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
+
+ rand.Seed(time.Now().UnixNano())
+ s := make([]rune, n)
+ for i := range s {
+ s[i] = letters[rand.Intn(len(letters))]
+ }
+ return string(s)
+}