forked from Knetic/govaluate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsanitizedParameters.go
43 lines (38 loc) · 902 Bytes
/
sanitizedParameters.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
package govaluate
// sanitizedParameters is a wrapper for Parameters that does sanitization as
// parameters are accessed.
type sanitizedParameters struct {
orig Parameters
}
func (p sanitizedParameters) Get(key string) (interface{}, error) {
value, err := p.orig.Get(key)
if err != nil {
return nil, err
}
return castToFloat64(value), nil
}
func castToFloat64(value interface{}) interface{} {
switch value.(type) {
case uint8:
return float64(value.(uint8))
case uint16:
return float64(value.(uint16))
case uint32:
return float64(value.(uint32))
case uint64:
return float64(value.(uint64))
case int8:
return float64(value.(int8))
case int16:
return float64(value.(int16))
case int32:
return float64(value.(int32))
case int64:
return float64(value.(int64))
case int:
return float64(value.(int))
case float32:
return float64(value.(float32))
}
return value
}