Пример #1
0
func beforeDisplay(hooks iface.Hooks) {
	defer func() {
		r := recover()
		if r != nil {
			fmt.Println(r)
		}
	}()
	hooks.Select("BeforeDisplay").Fire()
}
Пример #2
0
// Special fields in query:
// parentf, sort, limit, skip, page
func processMap(inp map[string]interface{}, hooks iface.Hooks) *data {
	d := &data{}
	if inp == nil {
		inp = map[string]interface{}{}
	}
	int_sch := map[string]interface{}{
		"type": "int",
	}
	sch := map[string]interface{}{
		//"parentf": 1,
		"sort": map[string]interface{}{
			"slice": true,
			"type":  "string",
		},
		"skip":  int_sch,
		"limit": int_sch,
		"page":  int_sch,
	}
	ex, err := sanitize.New(sch)
	if err != nil {
		panic(err)
	}
	dat, err := ex.Extract(inp)
	if err != nil {
		panic(err)
	}
	for i := range sch {
		delete(inp, i)
	}
	mods := &Mods{}
	//if dat["parentf"] != nil {
	//	d.parentField = dat["parentf"].(string)
	//}
	if dat["sort"] != nil {
		mods.sort = convert.ToStringSlice(dat["sort"].([]interface{}))
	}
	if dat["skip"] != nil {
		mods.skip = int(dat["skip"].(int64))
	}
	if dat["limit"] != nil {
		mods.limit = int(dat["limit"].(int64))
	} else {
		mods.limit = 20
	}
	if dat["page"] != nil {
		page := int(dat["page"].(int64))
		mods.skip = (page - 1) * mods.limit
	}
	d.mods = mods
	if hooks != nil {
		hooks.Select("ProcessMap").Fire(inp) // We should let the subscriber now the subject name maybe.
	}
	d.query = toQuery(inp)
	return d
}
Пример #3
0
// Special fields in query:
// parentf, sort, limit, skip, page
func processQuery(hooks iface.Hooks, coll string, scheme, inp map[string]interface{}) *data {
	d := &data{}
	if inp == nil {
		inp = map[string]interface{}{}
	}
	intSch := map[string]interface{}{
		"type": "int",
	}
	sch := map[string]interface{}{
		//"parentf": 1,
		"sort":  1,
		"skip":  intSch,
		"limit": intSch,
		"page":  intSch,
	}
	ex, err := sanitize.New(sch)
	if err != nil {
		panic(err)
	}
	dat, err := ex.Extract(inp)
	if err != nil {
		panic(err)
	}
	for i := range sch {
		delete(inp, i)
	}
	mods := &Mods{}
	//if dat["parentf"] != nil {
	//	d.parentField = dat["parentf"].(string)
	//}
	if dat["skip"] != nil {
		mods.skip = int(dat["skip"].(int64))
	}
	if dat["limit"] != nil {
		mods.limit = int(dat["limit"].(int64))
	} else {
		mods.limit = 20
	}
	if dat["page"] != nil {
		page := int(dat["page"].(int64))
		mods.skip = (page - 1) * mods.limit
	}
	if dat["sort"] != nil {
		mods.sort = []string{dat["sort"].(string)}
	}
	d.mods = mods
	if hooks != nil {
		hooks.Select("ProcessQuery").Fire(inp) // We should let the subscriber now the subject name maybe.
		hooks.Select(coll + "ProcessQuery").Fire(inp)
	}
	if scheme != nil && len(scheme) != 0 {
		ex, err = sanitize.New(scheme)
		if err != nil {
			panic(err)
		}
		hooks.Select("SanitizerMangler").Fire(ex)
		dat, err := ex.Extract(inp)
		if err != nil {
			panic(err)
		}
		inp = dat
	}
	d.query = toQuery(inp)
	return d
}