本文整理匯總了Golang中github.com/dop251/otto.Value.Export方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.Export方法的具體用法?Golang Value.Export怎麽用?Golang Value.Export使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dop251/otto.Value
的用法示例。
在下文中一共展示了Value.Export方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetBool
//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
}
示例2: GetAuthorization
//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
}
示例3: GetTransaction
//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
}
示例4: GetString
//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
}
示例5: GetList
//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
}
示例6: GetMap
//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
}
示例7: GetStringList
//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
}