當前位置: 首頁>>代碼示例>>Golang>>正文


Golang otto.Value類代碼示例

本文整理匯總了Golang中github.com/dop251/otto.Value的典型用法代碼示例。如果您正苦於以下問題:Golang Value類的具體用法?Golang Value怎麽用?Golang Value使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Value類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetInt64

//GetInt64 gets int64 from otto value
func GetInt64(value otto.Value) (result int64, err error) {
	result, err = value.ToInteger()
	if err != nil {
		err = fmt.Errorf(wrongArgumentType, value, "int64")
	}
	return
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:8,代碼來源:otto.go

示例2: 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
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:9,代碼來源:otto.go

示例3: 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
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:9,代碼來源:otto.go

示例4: 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
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:9,代碼來源:otto.go

示例5: 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
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:9,代碼來源:otto.go

示例6: 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
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:12,代碼來源:otto.go

示例7: 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
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:12,代碼來源:otto.go

示例8: GetOrCreateTransaction

//GetOrCreateTransaction gets transaction from otto value or creates new is otto value is null
func (env *Environment) GetOrCreateTransaction(value otto.Value) (transaction.Transaction, bool, error) {
	if !value.IsNull() {
		tx, err := GetTransaction(value)
		return tx, false, err
	}
	dataStore := env.DataStore
	tx, err := dataStore.Begin()
	if err != nil {
		return nil, false, fmt.Errorf("Error creating transaction: %v", err.Error())
	}
	return tx, true, nil
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:13,代碼來源:otto.go

示例9: 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
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:18,代碼來源:otto.go


注:本文中的github.com/dop251/otto.Value類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。