本文整理汇总了Golang中github.com/robertkrimen/otto.Value.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.IsDefined方法的具体用法?Golang Value.IsDefined怎么用?Golang Value.IsDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/robertkrimen/otto.Value
的用法示例。
在下文中一共展示了Value.IsDefined方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: execScript
// Execute Javascript
func (sh *Shell) execScript(editor bool) stateFn {
var out string
var value otto.Value
var err error
if !editor {
tmp := strings.TrimPrefix(sh.input, RunJavascript) // remove script meta-command
value, err = sh.jsengine.Run(tmp)
} else {
value, err = sh.jsengine.Run(sh.input)
}
if err != nil {
out = err.Error()
} else if value.IsDefined() {
out = value.String()
}
sh.write(out)
if !editor {
sh.line.AppendHistory(sh.input)
}
return bqlPrompt
}
示例3: 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{})
}
示例4: 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 {
//.........这里部分代码省略.........