當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Filter.Field方法代碼示例

本文整理匯總了Golang中github.com/eaciit/dbox.Filter.Field方法的典型用法代碼示例。如果您正苦於以下問題:Golang Filter.Field方法的具體用法?Golang Filter.Field怎麽用?Golang Filter.Field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/eaciit/dbox.Filter的用法示例。


在下文中一共展示了Filter.Field方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:26,代碼來源:xlsx_query.go

示例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
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:57,代碼來源:query.go

示例3: BuildFilter

func (fb *FilterBuilder) BuildFilter(f *dbox.Filter) (interface{}, error) {
	fm := M{}
	f.Field = strings.ToLower(f.Field)
	if f.Op == dbox.FilterOpEqual {
		fm.Set(f.Field, f.Value)
	} else if f.Op == dbox.FilterOpNoEqual {
		fm.Set(f.Field, M{}.Set("$ne", f.Value))
	} else if f.Op == dbox.FilterOpContains {
		fm.Set(f.Field, M{}.
			Set("$regex", fmt.Sprintf(".*%s.*", f.Value)).
			Set("$options", "i"))
	} else if f.Op == dbox.FilterOpStartWith {
		fm.Set(f.Field, M{}.
			Set("$regex", fmt.Sprintf("^%s.*$", f.Value)).
			Set("$options", "i"))
	} else if f.Op == dbox.FilterOpEndWith {
		fm.Set(f.Field, M{}.
			Set("$regex", fmt.Sprintf("^.*%s$", f.Value)).
			Set("$options", "i"))
	} else if f.Op == dbox.FilterOpIn {
		fm.Set(f.Field, M{}.Set("$in", f.Value))
	} else if f.Op == dbox.FilterOpNin {
		fm.Set(f.Field, M{}.Set("$nin", f.Value))
	} else if f.Op == dbox.FilterOpGt {
		fm.Set(f.Field, M{}.Set("$gt", f.Value))
	} else if f.Op == dbox.FilterOpGte {
		fm.Set(f.Field, M{}.Set("$gte", f.Value))
	} else if f.Op == dbox.FilterOpLt {
		fm.Set(f.Field, M{}.Set("$lt", f.Value))
	} else if f.Op == dbox.FilterOpLte {
		fm.Set(f.Field, M{}.Set("$lte", f.Value))
	} else if f.Op == dbox.FilterOpOr || f.Op == dbox.FilterOpAnd {
		bfs := []interface{}{}
		fs := f.Value.([]*dbox.Filter)
		for _, ff := range fs {
			bf, eb := fb.BuildFilter(ff)
			if eb == nil {
				bfs = append(bfs, bf)
			}
		}

		fm.Set(f.Op, bfs)
	} else {
		return nil, fmt.Errorf("Filter Op %s is not defined", f.Op)
	}
	return fm, nil
}
開發者ID:rinosukmandityo,項目名稱:dbox,代碼行數:47,代碼來源:csv_filter.go


注:本文中的github.com/eaciit/dbox.Filter.Field方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。