-
Notifications
You must be signed in to change notification settings - Fork 5
/
helpers.go
50 lines (42 loc) · 883 Bytes
/
helpers.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
48
49
50
package tormenta
import (
"encoding/json"
"log"
"math/rand"
"time"
)
func RandomiseRecords(slice []Record) {
for i := range slice {
j := rand.Intn(i + 1)
slice[i], slice[j] = slice[j], slice[i]
}
}
func MemberString(valid []string, target string) bool {
for _, validOption := range valid {
if target == validOption {
return true
}
}
return false
}
var nonContentWords = []string{"on", "at", "the", "in", "a"}
func removeNonContentWords(strings []string) (results []string) {
for _, s := range strings {
if !MemberString(nonContentWords, s) {
results = append(results, s)
}
}
return
}
func timerMiliseconds(t time.Time) int {
t1 := time.Now()
duration := t1.Sub(t)
return int(duration.Seconds() * 1000)
}
func ToJSON(m interface{}) string {
js, err := json.MarshalIndent(m, "", " ")
if err != nil {
log.Fatal(err)
}
return string(js)
}