Exemplo n.º 1
0
//GetBool gets bool from otto value
func GetBool(value otto.Value) (bool, error) {
	rawBool, _ := value.Export()
	result, ok := rawBool.(bool)
	if !ok {
		return false, fmt.Errorf(wrongArgumentType, rawBool, "bool")
	}
	return result, nil
}
Exemplo n.º 2
0
//GetAuthorization gets Transaction from otto value
func GetAuthorization(value otto.Value) (schema.Authorization, error) {
	rawAuthorization, _ := value.Export()
	result, ok := rawAuthorization.(schema.Authorization)
	if !ok {
		return nil, fmt.Errorf(wrongArgumentType, rawAuthorization, "Authorization")
	}
	return result, nil
}
Exemplo n.º 3
0
//GetTransaction gets Transaction from otto value
func GetTransaction(value otto.Value) (transaction.Transaction, error) {
	rawTransaction, _ := value.Export()
	result, ok := rawTransaction.(transaction.Transaction)
	if !ok {
		return nil, fmt.Errorf(wrongArgumentType, rawTransaction, "Transaction")
	}
	return result, nil
}
Exemplo n.º 4
0
//GetString gets string from otto value
func GetString(value otto.Value) (string, error) {
	rawString, _ := value.Export()
	result, ok := rawString.(string)
	if !ok {
		return "", fmt.Errorf(wrongArgumentType, rawString, "string")
	}
	return result, nil
}
Exemplo n.º 5
0
//GetList gets []interface{} from otto value
func GetList(value otto.Value) ([]interface{}, error) {
	rawSlice, _ := value.Export()
	result, ok := rawSlice.([]interface{})
	if !ok {
		return []interface{}{}, fmt.Errorf(wrongArgumentType, rawSlice, "array")
	}
	for i, value := range result {
		result[i] = ConvertOttoToGo(value)
	}
	return result, nil
}
Exemplo n.º 6
0
//GetMap gets map[string]interace{} from otto value
func GetMap(value otto.Value) (map[string]interface{}, error) {
	rawMap, _ := value.Export()
	result, ok := rawMap.(map[string]interface{})
	if !ok {
		return map[string]interface{}{}, fmt.Errorf(wrongArgumentType, rawMap, "Object")
	}
	for key, value := range result {
		result[key] = ConvertOttoToGo(value)
	}
	return result, nil
}
Exemplo n.º 7
0
//GetStringList gets []string  from otto value
func GetStringList(value otto.Value) ([]string, error) {
	rawSlice, _ := value.Export()
	errMessage := fmt.Errorf(wrongArgumentType, rawSlice, "array of strings")
	rawResult, ok := rawSlice.([]interface{})
	if !ok {
		return []string{}, errMessage
	}
	result := []string{}
	for _, rawItem := range rawResult {
		item, ok := rawItem.(string)
		if !ok {
			return []string{}, errMessage
		}
		result = append(result, item)
	}
	return result, nil
}