-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutil.go
80 lines (69 loc) · 1.2 KB
/
util.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
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
80
package iopipe
import (
"crypto/rand"
"io"
"reflect"
"runtime"
)
func coerceNumeric(x interface{}) interface{} {
switch x := x.(type) {
case uint8:
return int64(x)
case int8:
return int64(x)
case uint16:
return int64(x)
case int16:
return int64(x)
case uint32:
return int64(x)
case int32:
return int64(x)
case uint64:
return int64(x)
case int64:
return int64(x)
case int:
return int64(x)
case float32:
return float64(x)
case float64:
return float64(x)
default:
return nil
}
}
func coerceString(x interface{}) interface{} {
switch x := x.(type) {
case string:
return string(x)
default:
return nil
}
}
func getFuncName(f interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
}
// False returns a pointer to false
func False() *bool {
b := false
return &b
}
// True returns a pointer to true
func True() *bool {
b := true
return &b
}
func strToBool(s string) *bool {
if s == "true" || s == "1" {
return True()
}
return False()
}
func generateUUID() string {
var uuid UUID
io.ReadFull(rand.Reader, uuid[:])
uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10
return uuid.String()
}