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


Golang Object.Get方法代碼示例

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


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

示例1: getString

func getString(obj *otto.Object, name string) (string, error) {
	v, err := obj.Get(name)
	if err != nil {
		return "", err
	}
	return v.ToString()
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:7,代碼來源:plugins.go

示例2: getInt

func getInt(obj *otto.Object, name string) (int64, error) {
	v, err := obj.Get(name)
	if err != nil {
		return -1, err
	}
	return v.ToInteger()
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:7,代碼來源:plugins.go

示例3: getViaData

func getViaData(obj *otto.Object) (predicates []interface{}, tags []string, ok bool) {
	argList, _ := obj.Get("_gremlin_values")
	if argList.Class() != "GoArray" {
		clog.Errorf("How is arglist not an array? Return nothing. %v", argList.Class())
		return nil, nil, false
	}
	argArray := argList.Object()
	lengthVal, _ := argArray.Get("length")
	length, _ := lengthVal.ToInteger()
	if length == 0 {
		predicates = []interface{}{}
	} else {
		zero, _ := argArray.Get("0")
		predicates = buildPathFromValue(zero)
	}
	if length >= 2 {
		one, _ := argArray.Get("1")
		if one.IsString() {
			tags = append(tags, one.String())
		} else if one.Class() == "Array" {
			tags = stringsFrom(one.Object())
		}
	}
	ok = true
	return
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:26,代碼來源:build_iterator.go

示例4: fields

func (ctx ppctx) fields(obj *otto.Object) []string {
	var (
		vals, methods []string
		seen          = make(map[string]bool)
	)
	add := func(k string) {
		if seen[k] || boringKeys[k] {
			return
		}
		seen[k] = true
		if v, _ := obj.Get(k); v.IsFunction() {
			methods = append(methods, k)
		} else {
			vals = append(vals, k)
		}
	}
	// add own properties
	ctx.doOwnProperties(obj.Value(), add)
	// add properties of the constructor
	if cp := constructorPrototype(obj); cp != nil {
		ctx.doOwnProperties(cp.Value(), add)
	}
	sort.Strings(vals)
	sort.Strings(methods)
	return append(vals, methods...)
}
開發者ID:Cisko-Rijken,項目名稱:go-expanse,代碼行數:26,代碼來源:pretty.go

示例5: propertiesOf

func propertiesOf(obj *otto.Object, name string) []string {
	val, _ := obj.Get(name)
	if val.IsUndefined() {
		return nil
	}
	export, _ := val.Export()
	return export.([]string)
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:8,代碼來源:build_iterator.go

示例6: getFirstArgAsMorphismChain

func getFirstArgAsMorphismChain(obj *otto.Object) *otto.Object {
	arg, _ := obj.Get("_gremlin_values")
	firstArg, _ := arg.Object().Get("0")
	if isVertexChain(firstArg.Object()) {
		return nil
	}
	return firstArg.Object()
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:8,代碼來源:build_iterator.go

示例7: constructorPrototype

func constructorPrototype(obj *otto.Object) *otto.Object {
	if v, _ := obj.Get("constructor"); v.Object() != nil {
		if v, _ = v.Object().Get("prototype"); v.Object() != nil {
			return v.Object()
		}
	}
	return nil
}
開發者ID:Xiaoyang-Zhu,項目名稱:go-ethereum,代碼行數:8,代碼來源:pretty.go

示例8: debugChain

func debugChain(obj *otto.Object) bool {
	val, _ := obj.Get("_gremlin_type")
	glog.V(2).Infoln(val)
	val, _ = obj.Get("_gremlin_prev")
	if val.IsObject() {
		return debugChain(val.Object())
	}
	return false
}
開發者ID:dwdm,項目名稱:clair,代碼行數:9,代碼來源:traversals.go

示例9: debugChain

func debugChain(obj *otto.Object) bool {
	val, _ := obj.Get("_gremlin_type")
	if clog.V(2) {
		clog.Infof("%v", val)
	}
	val, _ = obj.Get("_gremlin_prev")
	if val.IsObject() {
		return debugChain(val.Object())
	}
	return false
}
開發者ID:kortschak,項目名稱:cayley,代碼行數:11,代碼來源:traversals.go

示例10: isVertexChain

func isVertexChain(obj *otto.Object) bool {
	val, _ := obj.Get("_gremlin_type")
	if val.String() == "vertex" {
		return true
	}
	val, _ = obj.Get("_gremlin_prev")
	if val.IsObject() {
		return isVertexChain(val.Object())
	}
	return false
}
開發者ID:lytics,項目名稱:cayley,代碼行數:11,代碼來源:environ.go

示例11: getStrings

func getStrings(obj *otto.Object, field string) []string {
	strings := make([]string, 0)
	val, _ := obj.Get(field)
	if !val.IsUndefined() {
		export, _ := val.Export()
		array := export.([]interface{})
		for _, arg := range array {
			strings = append(strings, arg.(string))
		}
	}
	return strings
}
開發者ID:karanja-simon,項目名稱:cayley,代碼行數:12,代碼來源:build_iterator.go

示例12: setHeader

func setHeader(o *otto.Object, h *http.Header) {
	header, _ := o.Get("header")
	headerIface, _ := header.Export()
	headerMap, ok := headerIface.(map[string]interface{})

	if ok {
		for k, v := range headerMap {
			strV, ok := v.(string)
			if ok {
				h.Set(k, strV)
			}
		}
	}
}
開發者ID:BlackEspresso,項目名稱:ServeJS,代碼行數:14,代碼來源:http.go

示例13: getFirstArgAsInt64

func getFirstArgAsInt64(obj *otto.Object) (int64, bool) {
	arg, err := obj.Get("_gremlin_values")
	if err != nil {
		return 0, false
	}
	firstArg, err := arg.Object().Get("0")
	if err != nil {
		return 0, false
	}
	if !firstArg.IsNumber() {
		return 0, false
	}
	v, err := firstArg.ToInteger()
	return v, err == nil
}
開發者ID:kortschak,項目名稱:cayley,代碼行數:15,代碼來源:build_iterator.go

示例14: stringsFrom

func stringsFrom(obj *otto.Object) []string {
	var output []string
	lengthValue, _ := obj.Get("length")
	length, _ := lengthValue.ToInteger()
	ulength := uint32(length)
	for i := uint32(0); i < ulength; i++ {
		name := strconv.FormatInt(int64(i), 10)
		value, err := obj.Get(name)
		if err != nil || !value.IsString() {
			continue
		}
		output = append(output, value.String())
	}
	return output
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:15,代碼來源:build_iterator.go

示例15: isBigNumber

func (ctx ppctx) isBigNumber(v *otto.Object) bool {
	// Handle numbers with custom constructor.
	if v, _ := v.Get("constructor"); v.Object() != nil {
		if strings.HasPrefix(toString(v.Object()), "function BigNumber") {
			return true
		}
	}
	// Handle default constructor.
	BigNumber, _ := ctx.vm.Object("BigNumber.prototype")
	if BigNumber == nil {
		return false
	}
	bv, _ := BigNumber.Call("isPrototypeOf", v)
	b, _ := bv.ToBoolean()
	return b
}
開發者ID:Xiaoyang-Zhu,項目名稱:go-ethereum,代碼行數:16,代碼來源:pretty.go


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