forked from ZeStream/zestream-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.go
47 lines (38 loc) · 939 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package utils
import (
"bytes"
"crypto/rand"
"encoding/binary"
"log"
math_rand "math/rand"
"strconv"
)
/*
VideoIDGen returns an unique videoID and appends the fileExtension to it,
it takes the fileExtensionas parameter
*/
func VideoIDGen(fileExtension string) string {
var b [8]byte
if _, err := rand.Read(b[:]); err != nil {
return err.Error()
}
var i int64 = int64(binary.LittleEndian.Uint64(b[:]))
math_rand.Seed(i)
// Generate a 8 digit random number
randomNumber := math_rand.Intn(99999999-10000000) + 10000000
// VideoID = (8-digit random number) + (file Name)
return strconv.Itoa(randomNumber) + fileExtension
}
// WrapStringInQuotes returns the string wrapped in quotes
func WrapStringInQuotes(str string) string {
var buff bytes.Buffer
buff.WriteString(str)
buff.WriteString(" ")
return buff.String()
}
// LogErr logs the given error
func LogErr(err error) {
if err != nil {
log.Println(err)
}
}