Beispiel #1
0
func getList(uni *context.Uni, noun string, params ...interface{}) []interface{} {
	values := convert.ListToMap(params...)
	desc, err := glue.Identify("/"+noun, uni.Opt["nouns"].(map[string]interface{}), values)
	inp, data, err := desc.CreateInputs(uni.FilterCreator)
	if err != nil {

		panic(err)
	}
	if data != nil {
		inp = append(inp, data)
	}
	module := uni.NewModule(desc.VerbLocation)
	if !module.Exists() {
		panic("Module does not exist.")
	}
	ins := module.Instance()
	ret := []interface{}{}
	ret_rec := func(i ...interface{}) {
		ret = i
	}
	ins.Method("Get").Call(ret_rec, inp...)
	return ret
}
Beispiel #2
0
// Mainly designed to work from Get or GetSingle
func getSub(uni *context.Uni, noun string, params ...interface{}) []interface{} {
	if uni.Route == nil && uni.Sentence == nil {
		panic("Nothing to do here.")
	}
	s := uni.Sentence
	r := uni.Route
	var path string
	var urls []map[string]interface{}
	if s.Verb != "Get" && s.Verb != "GetSingle" {
		path = "/" + strings.Join(r.Words, "/") + "/" + noun
		urls = append(urls, r.Queries...)
		urls = append(urls, convert.ListToMap(params...))
	} else {
		path = "/" + strings.Join(r.Words, "/") + "/" + noun
		urls = append(urls, r.Queries[:len(r.Queries)-1]...)
		urls = append(urls, convert.ListToMap(params...))
	}
	desc, err := glue.Identify(path, uni.Opt["nouns"].(map[string]interface{}), lang.EncodeQueries(urls, false))
	inp, data, err := desc.CreateInputs(uni.FilterCreator)
	if err != nil {
		panic(err)
	}
	if data != nil {
		inp = append(inp, data)
	}
	module := uni.NewModule(desc.VerbLocation)
	if !module.Exists() {
		panic("Module does not exist.")
	}
	ins := module.Instance()
	ret := []interface{}{}
	ret_rec := func(i ...interface{}) {
		ret = i
	}
	ins.Method(uni.Sentence.Verb).Call(ret_rec, inp...)
	return ret
}
Beispiel #3
0
func (t *Top) route() error {
	uni := t.uni
	paths := strings.Split(uni.Path, "/")
	if t.config.ServeFiles && strings.Index(paths[len(paths)-1], ".") != -1 {
		t.serveFile()
		return nil
	}
	t.buildUser()
	var ret []interface{}
	ret_rec := func(i ...interface{}) {
		ret = i
	}
	nouns, ok := uni.Opt["nouns"].(map[string]interface{})
	if !ok {
		nouns = map[string]interface{}{
			"options": opt_def,
		}
	}
	if _, ok := nouns["options"]; !ok {
		nouns["options"] = opt_def
	}
	uni.FilterCreator = func(c string, input map[string]interface{}) iface.Filter {
		return filterCreator(uni.Db, uni.Ev, nouns, input, c)
	}
	desc, err := glue.Identify(uni.Path, nouns, convert.Mapify(uni.Req.Form))
	if err != nil {
		display.D(uni)
		return nil
	}
	default_level, _ := numcon.Int(uni.Opt["default_level"])
	levi, ok := jsonp.Get(uni.Opt, fmt.Sprintf("nouns.%v.verbs.%v.level", desc.Sentence.Noun, desc.Sentence.Verb))
	if !ok {
		levi = default_level
	}
	lev, _ := numcon.Int(levi)
	if scut.Ulev(uni.Dat["_user"]) < lev {
		return fmt.Errorf("Not allowed.")
	}
	inp, data, err := desc.CreateInputs(uni.FilterCreator)
	if err != nil {
		return err
	}
	if data != nil {
		if desc.Sentence.Noun != "options" {
			data, err = t.validate(desc.Sentence.Noun, desc.Sentence.Verb, data)
			if err != nil {
				return err
			}
		}
		inp = append(inp, data)
	}
	uni.Route = desc.Route
	uni.Sentence = desc.Sentence
	module := t.uni.NewModule(desc.VerbLocation)
	if !module.Exists() {
		return fmt.Errorf("Unkown module.")
	}
	ins := module.Instance()
	ins.Method(uni.Sentence.Verb).Call(ret_rec, inp...)
	if uni.Req.Method == "GET" {
		uni.Dat["main_noun"] = desc.Sentence.Noun
		uni.Dat["_points"] = []string{desc.Sentence.Noun + "/" + desc.Sentence.Verb, desc.VerbLocation + "/" + desc.Sentence.Verb}
		t.Get(ret)
	} else {
		t.Post(ret)
	}
	return nil
}