Beispiel #1
0
// guessValue attemtps to bruteforce all supported types.
func guessValue(value *jason.Value) interface{} {
	if v, err := value.Int64(); err == nil {
		return v
	} else if v, err := value.Float64(); err == nil {
		return v
	} else if v, err := value.Boolean(); err == nil {
		return v
	} else if v, err := value.String(); err == nil {
		return v
	} else if v, err := value.Array(); err == nil {
		// if we get an array, calculate average

		// empty array, treat as zero
		if len(v) == 0 {
			return 0
		}

		avg := averageJason(v)

		// cast to int64 for Int64 values
		if _, err := v[0].Int64(); err == nil {
			return int64(avg)
		}

		return avg
	}

	return nil
}
Beispiel #2
0
// guessValue attemtps to bruteforce all supported types.
func guessValue(value *jason.Value) interface{} {
	if v, err := value.Int64(); err == nil {
		return v
	} else if v, err := value.Float64(); err == nil {
		return v
	} else if v, err := value.Boolean(); err == nil {
		return v
	} else if v, err := value.String(); err == nil {
		return v
	}

	return nil
}