-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
79 lines (72 loc) · 1.19 KB
/
utils.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
package Gorage
import (
"fmt"
"hash/fnv"
"os"
)
func gprint(a, s string) {
fmt.Printf("[Gorage](%s) - %s\n", a, s)
}
func fileExists(path string) bool {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}
return true
}
func computeHash(data []interface{}) uint32 {
var h string
for _, v := range data {
switch v.(type) {
case string:
h += v.(string)
break
case int:
h += fmt.Sprintf("%d", v)
break
case float64:
h += fmt.Sprintf("%d", int(v.(float64)))
break
case float32:
h += fmt.Sprintf("%d", int(v.(float32)))
break
case bool:
if v.(bool) {
h += "True"
} else {
h += "False"
}
}
}
ha := fnv.New32a()
ha.Write([]byte(h))
return ha.Sum32()
}
func compareRows(a, b []interface{}) bool {
return computeHash(a) == computeHash(b)
}
func validateDatatype(is interface{}, c Column) bool {
switch is.(type) {
case int:
if c.Datatype != INT {
return false
}
case string:
if c.Datatype != STRING {
return false
}
case bool:
if c.Datatype != BOOLEAN {
return false
}
case float64:
if c.Datatype != FLOAT {
return false
}
case float32:
if c.Datatype != FLOAT {
return false
}
}
return true
}