-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
78 lines (70 loc) · 1.23 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
package rds
import (
"fmt"
"time"
"math"
"github.com/rs/rest-layer/schema/query"
)
// Determine if value is numeric.
// Numeric values are all ints, floats, time values.
func isNumeric(v ...query.Value) bool {
switch v[0].(type) {
case int, int8, int16, int32, int64, float32, float64, time.Time:
return true
default:
return false
}
}
// todo - better?
// todo - See toFloat64
func valueToFloat(v query.Value) float64 {
if x, ok := interface{}(v).(int); ok {
return float64(x)
}
if x, ok := interface{}(v).(time.Time); ok {
return float64(x.Nanosecond())
}
if x, ok := interface{}(v).(float64); ok {
return x
}
return -1.0
}
func toFloat64(in query.Value) float64 {
switch v := in.(type) {
case float64:
return v
case float32:
return float64(v)
}
return math.NaN()
}
// todo -1 ?
func toInt(in query.Value) int {
switch v := in.(type) {
case int:
return v
case int8:
return int(v)
case int16:
return int(v)
case int32:
return int(v)
case int64:
return int(v)
}
return -1
}
// todo - delete it?
func inSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func pr(v ...interface{}) {
for _, i := range v {
fmt.Printf("%#v\n", i)
}
}