mirror of
https://github.com/hanzoai/eval.git
synced 2026-09-30 21:47:09 +00:00
Module path renamed to github.com/hanzoai/eval and the Go package renamed from govaluate to eval. Evaluation, parsing, lexing, and operator behavior are unchanged; MIT license and George Lester attribution retained. See NOTICE for lineage.
44 lines
824 B
Go
44 lines
824 B
Go
package eval
|
|
|
|
// 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 := value.(type) {
|
|
case uint8:
|
|
return float64(value)
|
|
case uint16:
|
|
return float64(value)
|
|
case uint32:
|
|
return float64(value)
|
|
case uint64:
|
|
return float64(value)
|
|
case int8:
|
|
return float64(value)
|
|
case int16:
|
|
return float64(value)
|
|
case int32:
|
|
return float64(value)
|
|
case int64:
|
|
return float64(value)
|
|
case int:
|
|
return float64(value)
|
|
case float32:
|
|
return float64(value)
|
|
}
|
|
|
|
return value
|
|
}
|