美文网首页
GO 调用脚本语言例子

GO 调用脚本语言例子

作者: vison_kong | 来源:发表于2017-11-09 12:35 被阅读0次

packagemain

import(

"encoding/json"

"fmt"

"github.com/robertkrimen/otto"

)

var    testJsonstring=`{

"name":"tim",

"age":10,

"sites":["Google","Runoob","Taobao"],

"memo":{"info":"淘宝"}

}`

funcmain(){

varmapStrmap[string]interface{}

json.Unmarshal([]byte(testJson),&mapStr)

fmt.Println(mapStr["sites"])

vm:=otto.New()

vm.Set("mapStr",mapStr)

vm.Set("sites",mapStr["sites"])

vm.Set("memo",mapStr["memo"])

srcScript:=`

A=100;

B=200;

C=100;

console.log("Thesiteslen"+sites.length);

console.log("Thememoinfo"+memo.info);

console.log("ThemapStr.memo.infois"+mapStr.memo.info);

varid=Math.random();

`

_,err:=vm.Run(srcScript)

iferr!=nil{

fmt.Println(err.Error())

}

v,_:=vm.Get("memo")

v1,_:=v.Export()

v2,_:=v1.(map[string]interface{})

fmt.Println(v2["info"])

}

相关文章

网友评论

      本文标题:GO 调用脚本语言例子

      本文链接:https://www.haomeiwen.com/subject/nrppmxtx.html