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


Golang Value.IsObject方法代碼示例

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


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

示例1: convertValToMysqlConnInfo

func convertValToMysqlConnInfo(v *otto.Value) *MysqlConnInfo {
	connInfo := &MysqlConnInfo{}

	if v.IsDefined() && v.IsObject() {
		obj := v.Object()
		// get username
		if u, err := obj.Get("username"); err == nil && u.IsString() {
			connInfo.Username, _ = u.ToString()
		}

		// get password
		if p, err := obj.Get("password"); err == nil && p.IsString() {
			connInfo.Password, _ = p.ToString()
		}

		// get host
		if h, err := obj.Get("host"); err == nil && h.IsString() {
			connInfo.Host, _ = h.ToString()
		}

		// get port
		if p, err := obj.Get("port"); err == nil && p.IsNumber() {
			connInfo.Port, _ = p.ToInteger()
		}
	}

	return connInfo
}
開發者ID:sfreiberg,項目名稱:shepherd,代碼行數:28,代碼來源:js_funcs.go

示例2: convertValToMap

func convertValToMap(v *otto.Value) map[string]interface{} {
	if v.IsDefined() && v.IsObject() {
		options, _ := v.Export()
		return options.(map[string]interface{})
	}
	return make(map[string]interface{})
}
開發者ID:sfreiberg,項目名稱:shepherd,代碼行數:7,代碼來源:js_funcs.go

示例3: formatOneLine

func formatOneLine(v otto.Value, limit int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		switch v.Class() {
		case "Array":
			return formatArrayOneLine(v, limit, seen)
		default:
			return formatObjectOneLine(v, limit, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
開發者ID:deoxxa,項目名稱:ottoext,代碼行數:30,代碼來源:print.go

示例4: printValue

func (ctx ppctx) printValue(v otto.Value, level int, inArray bool) {
	switch {
	case v.IsObject():
		ctx.printObject(v.Object(), level, inArray)
	case v.IsNull():
		specialColor.Print("null")
	case v.IsUndefined():
		specialColor.Print("undefined")
	case v.IsString():
		s, _ := v.ToString()
		stringColor.Printf("%q", s)
	case v.IsBoolean():
		b, _ := v.ToBoolean()
		specialColor.Printf("%t", b)
	case v.IsNaN():
		numberColor.Printf("NaN")
	case v.IsNumber():
		s, _ := v.ToString()
		numberColor.Printf("%s", s)
	default:
		fmt.Printf("<unprintable>")
	}
}
開發者ID:Xiaoyang-Zhu,項目名稱:go-ethereum,代碼行數:23,代碼來源:pretty.go

示例5: formatIndent

func formatIndent(v otto.Value, width, indent, limit, level, additional int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		if d, err := formatOneLine(v, limit, seen); err != nil {
			return "", err
		} else if level*indent+additional+len(d) <= width {
			return d, nil
		}

		switch v.Class() {
		case "Array":
			return formatArray(v, width, indent, limit, level, seen)
		default:
			return formatObject(v, width, indent, limit, level, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
開發者ID:deoxxa,項目名稱:ottoext,代碼行數:36,代碼來源:print.go


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