-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmisc.go
More file actions
79 lines (67 loc) · 1.77 KB
/
misc.go
File metadata and controls
79 lines (67 loc) · 1.77 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package gofaker
import (
"encoding/hex"
"math/rand"
"github.com/tinygg/gofaker/data"
)
// Bool will generate a random boolean value
func Bool() bool {
return randIntRange(0, 1) == 1
}
// UUID (version 4) will generate a random unique identifier based upon random nunbers
// Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
func UUID() string {
version := byte(4)
uuid := make([]byte, 16)
rand.Read(uuid)
// Set version
uuid[6] = (uuid[6] & 0x0f) | (version << 4)
// Set variant
uuid[8] = (uuid[8] & 0xbf) | 0x80
buf := make([]byte, 36)
var dash byte = '-'
hex.Encode(buf[0:8], uuid[0:4])
buf[8] = dash
hex.Encode(buf[9:13], uuid[4:6])
buf[13] = dash
hex.Encode(buf[14:18], uuid[6:8])
buf[18] = dash
hex.Encode(buf[19:23], uuid[8:10])
buf[23] = dash
hex.Encode(buf[24:], uuid[10:])
return string(buf)
}
// Categories will return a map string array of available data categories and sub categories
func Categories() map[string][]string {
types := make(map[string][]string)
for category, subCategoriesMap := range data.Data() {
subCategories := make([]string, 0)
for subType := range subCategoriesMap {
subCategories = append(subCategories, subType)
}
types[category] = subCategories
}
return types
}
func addMiscLookup() {
AddFuncLookup("uuid", Info{
Display: "UUID",
Category: "misc",
Description: "Random uuid",
Example: "590c1440-9888-45b0-bd51-a817ee07c3f2",
Output: "string",
Call: func(m *map[string][]string, info *Info) (interface{}, error) {
return UUID(), nil
},
})
AddFuncLookup("bool", Info{
Display: "Boolean",
Category: "misc",
Description: "Random boolean",
Example: "true",
Output: "bool",
Call: func(m *map[string][]string, info *Info) (interface{}, error) {
return Bool(), nil
},
})
}