本文整理匯總了Golang中github.com/eaciit/dbox.Filter.Value方法的典型用法代碼示例。如果您正苦於以下問題:Golang Filter.Value方法的具體用法?Golang Filter.Value怎麽用?Golang Filter.Value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eaciit/dbox.Filter
的用法示例。
在下文中一共展示了Filter.Value方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ReadVariable
func ReadVariable(f *dbox.Filter, in toolkit.M) *dbox.Filter {
f.Field = strings.ToLower(f.Field)
if (f.Op == "$and" || f.Op == "$or") && strings.Contains(reflect.TypeOf(f.Value).String(), "dbox.Filter") {
fs := f.Value.([]*dbox.Filter)
for i, ff := range fs {
bf := ReadVariable(ff, in)
fs[i] = bf
}
f.Value = fs
} else {
if reflect.TypeOf(f.Value).Kind() == reflect.Slice {
fSlice := f.Value.([]interface{})
// nilai fSlice : [@name1 @name2]
for i := 0; i < len(fSlice); i++ {
// nilai fSlice [i] : @name1
if len(cast.ToString(f.Value)) > 0 && string(cast.ToString(fSlice[i])[0]) == "@" {
fSlice[i] = in.Get(cast.ToString(fSlice[i]), "")
}
}
f.Value = fSlice
} else if len(cast.ToString(f.Value)) > 0 && string(cast.ToString(f.Value)[0]) == "@" {
f.Value = in.Get(cast.ToString(f.Value), "")
}
}
return f
}
示例2: ReadVariable
func ReadVariable(f *dbox.Filter, in toolkit.M) *dbox.Filter {
f.Field = strings.ToLower(f.Field)
if (f.Op == "$and" || f.Op == "$or") &&
strings.Contains(reflect.TypeOf(f.Value).String(), "dbox.Filter") {
fs := f.Value.([]*dbox.Filter)
/* nilai fs : [0xc082059590 0xc0820595c0]*/
for i, ff := range fs {
/* nilai ff[0] : &{umur $gt @age} && ff[1] : &{name $eq @nama}*/
bf := ReadVariable(ff, in)
/* nilai bf[0] : &{umur $gt 25} && bf[1] : &{name $eq Kane}*/
fs[i] = bf
}
f.Value = fs
return f
} else {
if reflect.TypeOf(f.Value).Kind() == reflect.Slice {
if strings.Contains(reflect.TypeOf(f.Value).String(), "interface") {
fSlice := f.Value.([]interface{})
/*nilai fSlice : [@name1 @name2]*/
for i := 0; i < len(fSlice); i++ {
/* nilai fSlice [i] : @name1*/
if string(cast.ToString(fSlice[i])[0]) == "@" {
for key, val := range in {
if cast.ToString(fSlice[i]) == key {
fSlice[i] = val
}
}
}
}
f.Value = fSlice
} else if strings.Contains(reflect.TypeOf(f.Value).String(), "string") {
fSlice := f.Value.([]string)
for i := 0; i < len(fSlice); i++ {
if string(fSlice[i][0]) == "@" {
for key, val := range in {
if fSlice[i] == key {
fSlice[i] = val.(string)
}
}
}
}
f.Value = fSlice
}
return f
} else {
if string(cast.ToString(f.Value)[0]) == "@" {
for key, val := range in {
if cast.ToString(f.Value) == key {
f.Value = val
}
}
}
return f
}
}
return f
}
示例3: CheckFilter
func (fb *FilterBuilder) CheckFilter(f *dbox.Filter, p M) *dbox.Filter {
if f.Op == "$or" || f.Op == "$and" {
fs := f.Value.([]*dbox.Filter)
for i, ff := range fs {
bf := fb.CheckFilter(ff, p)
fs[i] = bf
}
return f
} else if f.Op == "$contains" {
// Println(f.Value)
for i, v := range f.Value.([]string) {
if p != nil {
f.Value.([]string)[i] = p.Get(v).(string)
} else {
f.Value.([]string)[i] = v
}
}
return f
} else {
if !IsSlice(f.Value) {
if strings.ToLower(Kind(f.Value).String()) == "string" {
foundSubstring := strings.Index(f.Value.(string), "@")
if foundSubstring != 0 {
return f
}
if strings.Contains(f.Value.(string), "@") {
f.Value = p.Get(f.Value.(string))
return f
}
}
} else {
for i, v := range f.Value.([]interface{}) {
foundSubstring := strings.Index(v.(string), "@")
if foundSubstring != 0 {
return f
}
switch Kind(v) {
case reflect.String:
stringValue := p.Get(v.(string))
f.Value.([]interface{})[i] = stringValue
case reflect.Int:
stringValue := ToInt(p.Get(v.(string)), ".")
f.Value.([]interface{})[i] = stringValue
case reflect.Bool:
f.Value.([]interface{})[i] = p.Get(v.(string)).(bool)
}
}
return f
}
}
return f
}
示例4: ReadVariable
func ReadVariable(f *dbox.Filter, in toolkit.M) *dbox.Filter {
if (f.Op == "$and" || f.Op == "$or") &&
strings.Contains(reflect.TypeOf(f.Value).String(), "dbox.Filter") {
fs := f.Value.([]*dbox.Filter)
// nilai fs : [0xc082059590 0xc0820595c0]
for i, ff := range fs {
// nilai ff[0] : &{umur $gt @age} && ff[1] : &{name $eq @nama}
bf := ReadVariable(ff, in)
// nilai bf[0] : &{umur $gt 25} && bf[1] : &{name $eq Kane}
fs[i] = bf
}
f.Value = fs
return f
} else {
if reflect.TypeOf(f.Value).Kind() == reflect.Slice {
fSlice := f.Value.([]interface{})
// nilai fSlice : [@name1 @name2]
for i := 0; i < len(fSlice); i++ {
// nilai fSlice [i] : @name1
if string(cast.ToString(fSlice[i])[0]) == "@" {
for key, val := range in {
if strings.Replace(cast.ToString(fSlice[i]), "@", "", 1) == key {
fSlice[i] = val
}
}
}
}
f.Value = fSlice
return f
} else {
if string(cast.ToString(f.Value)[0]) == "@" {
for key, val := range in {
if strings.Replace(cast.ToString(f.Value), "@", "", 1) == key {
f.Value = val
}
}
}
return f
}
}
return f
}