当前位置: 首页>>代码示例>>Golang>>正文


Golang Value.ToString方法代码示例

本文整理汇总了Golang中github.com/robertkrimen/otto.Value.ToString方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.ToString方法的具体用法?Golang Value.ToString怎么用?Golang Value.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/robertkrimen/otto.Value的用法示例。


在下文中一共展示了Value.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: fetchConfig

func fetchConfig(funcname string, name string, config interface{}) bool {

	var ret otto.Value
	var err error

	if name == "" {
		ret, err = jsVM.Call(funcname, nil)
	} else {
		ret, err = jsVM.Call(funcname, nil, name)
	}

	if err != nil {
		log.Printf("call failed, in '%s', %v", funcname, err)
		return false
	}

	jsonConfig, err := ret.ToString()

	if err != nil {
		log.Println(err)
		return false
	}

	if err := json.Unmarshal([]byte(jsonConfig), config); err != nil {
		log.Printf("json.Unmarshal failed, in '%s', %v", funcname, err)
		return false
	}

	return true
}
开发者ID:chogaths,项目名称:robin,代码行数:30,代码来源:svccfg.go

示例2: MustResolve

func (rm refMap) MustResolve(ref otto.Value) interface{} {
	key, err := ref.ToString()
	if err != nil {
		panic(err)
	}
	v, ok := rm[key]
	if !ok {
		panic(fmt.Sprintf("Invalid reference: %s", key))
	}
	return v
}
开发者ID:surma-dump,项目名称:gophernamedray,代码行数:11,代码来源:sceneparser.go

示例3: ottoRetString

func (p *PacSandbox) ottoRetString(v otto.Value, rte error) (string, error) {
	if rte != nil {
		return "", rte
	}

	ret, err := v.ToString()

	if err != nil {
		return "", err
	}

	return ret, nil
}
开发者ID:mikesimons,项目名称:pacyak,代码行数:13,代码来源:otto_utils.go

示例4: ottoToGo

// Converts an Otto value to a Go value. Handles all JSON-compatible types.
func ottoToGo(value otto.Value) (interface{}, error) {
	if value.IsBoolean() {
		return value.ToBoolean()
	} else if value.IsNull() || value.IsUndefined() {
		return nil, nil
	} else if value.IsNumber() {
		return value.ToFloat()
	} else if value.IsString() {
		return value.ToString()
	} else {
		switch value.Class() {
		case "Array":
			return ottoToGoArray(value.Object())
		}
	}
	return nil, fmt.Errorf("Unsupported Otto value: %v", value)
}
开发者ID:steveyen,项目名称:walrus,代码行数:18,代码来源:js_map_fn.go

示例5: buildIteratorFromValue

func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
	if val.IsNull() || val.IsUndefined() {
		return ts.GetNodesAllIterator()
	}
	if val.IsPrimitive() {
		thing, _ := val.Export()
		switch v := thing.(type) {
		case string:
			it := ts.MakeFixed()
			it.AddValue(ts.GetIdFor(v))
			return it
		default:
			glog.Errorln("Trying to build unknown primitive value.")
		}
	}
	switch val.Class() {
	case "Object":
		return buildIteratorTree(val.Object(), ts)
	case "Array":
		// Had better be an array of strings
		strings := makeListOfStringsFromArrayValue(val.Object())
		it := ts.MakeFixed()
		for _, x := range strings {
			it.AddValue(ts.GetIdFor(x))
		}
		return it
	case "Number":
		fallthrough
	case "Boolean":
		fallthrough
	case "Date":
		fallthrough
	case "String":
		it := ts.MakeFixed()
		str, _ := val.ToString()
		it.AddValue(ts.GetIdFor(str))
		return it
	default:
		glog.Errorln("Trying to handle unsupported Javascript value.")
		return graph.NewNullIterator()
	}
}
开发者ID:karanja-simon,项目名称:cayley,代码行数:42,代码来源:build_iterator.go

示例6: convertToPrimitive

func convertToPrimitive(v otto.Value) interface{} {
	if v.IsBoolean() {
		v_b, err := v.ToBoolean()
		if err != nil {
			log.Printf("Error converting to boolean")
		}
		return v_b
	} else if v.IsNumber() {
		v_f, err := v.ToFloat()
		if err != nil {
			log.Printf("Error converting to float")
		}
		return v_f
	} else {
		v_s, err := v.ToString()
		if err != nil {
			log.Printf("Error converting to boolean")
		}
		return v_s
	}
	return nil
}
开发者ID:mschoch,项目名称:tuq,代码行数:22,代码来源:otto_util.go

示例7: 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

示例8: getSample

// Helper function to populate a sample structure with a single sample
func (sr *SampleReader) getSample() (*Sample, error) {

	var err error
	var v otto.Value

	s := new(Sample)

	// Extract date field from javascript runtime
	v, err = sr.vm.Get("date")
	if err != nil {
		return nil, err
	}

	if !v.IsDefined() {
		return nil, errors.New("date not defined")
	}

	ds, err := v.ToString()
	if err != nil {
		return nil, err
	}

	s.Date, err = time.Parse("2006-01-02T15:04:05", ds)
	if err != nil {
		return nil, err
	}

	// Extract latitude field from javascript runtime
	v, err = sr.vm.Get("latitude")
	if err != nil {
		return nil, err
	}

	if !v.IsDefined() {
		return nil, errors.New("latitude not defined")
	}

	s.Latitude, err = v.ToFloat()
	if err != nil {
		return nil, err
	}

	// Extract longitude field from javascript runtime
	v, err = sr.vm.Get("longitude")
	if err != nil {
		return nil, err
	}

	if !v.IsDefined() {
		return nil, errors.New("longitude not defined")
	}

	s.Longitude, err = v.ToFloat()
	if err != nil {
		return nil, err
	}

	// Extract altitude field from javascript runtime
	v, err = sr.vm.Get("altitude")
	if err != nil {
		return nil, err
	}

	if !v.IsDefined() {
		return nil, errors.New("altitude not defined")
	}

	s.Altitude, err = v.ToFloat()
	if err != nil {
		return nil, err
	}

	// Extract value field from javascript runtime
	v, err = sr.vm.Get("value")
	if err != nil {
		return nil, err
	}

	if !v.IsDefined() {
		return nil, errors.New("value not defined")
	}

	s.Value, err = v.ToFloat()
	if err != nil {
		return nil, err
	}

	// Extract unit field from javascript runtime
	v, err = sr.vm.Get("unit")
	if err != nil {
		return nil, err
	}

	if !v.IsDefined() {
		return nil, errors.New("unit not defined")
	}

	s.Unit, err = v.ToString()
	if err != nil {
//.........这里部分代码省略.........
开发者ID:corebob,项目名称:SampleConverter,代码行数:101,代码来源:SampleReader.go


注:本文中的github.com/robertkrimen/otto.Value.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。