本文整理匯總了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 {
//.........這裏部分代碼省略.........