mirror of
https://github.com/astaxie/beego.git
synced 2024-12-24 02:30:49 +00:00
44 lines
902 B
Go
44 lines
902 B
Go
|
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
|
||
|
}
|