Beispiel #1
0
func (t *Top) Get(ret []interface{}) {
	uni := t.uni
	ran := verbinfo.NewRanalyzer(ret)
	if ran.HadError() {
		display.DErr(uni, ran.Error())
		return
	}
	burnResults(uni.Dat, "main", ran.NonErrors())
	display.D(uni)
}
Beispiel #2
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
}