本文整理汇总了Golang中github.com/couchbaselabs/dparval.Value.Value方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.Value方法的具体用法?Golang Value.Value怎么用?Golang Value.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbaselabs/dparval.Value
的用法示例。
在下文中一共展示了Value.Value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Evaluate
func (this *FunctionCallSplit) Evaluate(item *dparval.Value) (*dparval.Value, error) {
// first evaluate the arguments
av, err := this.Operands[0].Expr.Evaluate(item)
if err != nil {
switch err := err.(type) {
case *dparval.Undefined:
// undefined returns null
return dparval.NewValue(nil), nil
default:
// any other error return to caller
return nil, err
}
// FIXME warn if arguments were wrong type?
if av.Type() != dparval.STRING {
return dparval.NewValue(nil), nil
}
}
var sep *dparval.Value = nil
if len(this.Operands) > 1 {
sep, err = this.Operands[1].Expr.Evaluate(item)
if err != nil {
switch err := err.(type) {
case *dparval.Undefined:
// undefined returns null
return dparval.NewValue(nil), nil
default:
// any other error return to caller
return nil, err
}
}
// FIXME warn if arguments were wrong type?
if sep.Type() != dparval.STRING {
return dparval.NewValue(nil), nil
}
}
var sa []string
if sep != nil {
sa = strings.Split(av.Value().(string),
sep.Value().(string))
} else {
sa = strings.Fields(av.Value().(string))
}
rv := make([]interface{}, len(sa))
for i, s := range sa {
rv[i] = s
}
return dparval.NewValue(rv), nil
}
示例2: Evaluate
func (this *CaseOperator) Evaluate(item *dparval.Value) (*dparval.Value, error) {
var switchItem *dparval.Value
if this.Switch != nil {
var err error
switchItem, err = this.Switch.Evaluate(item)
if err != nil {
return nil, err
}
}
// walk through the WhenThens in order
for _, WhenThen := range this.WhenThens {
// evalute the when
whenVal, err := WhenThen.When.Evaluate(item)
if err != nil {
switch err := err.(type) {
case *dparval.Undefined:
// MISSING is not true, keep looking
continue
default:
// any other error should be returned to caller
return nil, err
}
}
var match bool
whenValVal := whenVal.Value()
if switchItem != nil {
if switchItem.Value() == whenValVal {
match = true
}
} else {
match = ValueInBooleanContext(whenValVal).(bool)
}
if match == true {
// evalauate the then
thenVal, err := WhenThen.Then.Evaluate(item)
if err != nil {
return nil, err
}
return thenVal, nil
}
}
// if we got this point, none of the WhenThen pairs were satisfied
// if there was an else, evaluate it and return
if this.Else != nil {
elseVal, err := this.Else.Evaluate(item)
if err != nil {
return nil, err
}
return elseVal, nil
}
// if there was no else, return null
return dparval.NewValue(nil), nil
}