Exemplo n.º 1
0
Arquivo: main.go Projeto: artwebs/aogo
func (this *DefaultModel) Aws(name string, args map[string]interface{}) map[string]interface{} {
	data, _ := json.Marshal(args)
	var notused string
	this.Drv.Conn()
	err := this.Drv.Db().QueryRow("SELECT aws($1,$2)", name, string(data)).Scan(&notused)
	defer this.Drv.Close()
	if err != nil {
		log.ErrorTag(this, err)
		return make(map[string]interface{})
	}
	result := make(map[string]interface{})
	json.Unmarshal([]byte(notused), &result)
	return result
}
Exemplo n.º 2
0
func (this *ControllerRegistor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	url := r.URL.String()
	log.InfoTag(this, url)
	if url == "/favicon.ico" {
		http.ServeFile(w, r, "./favicon.ico")
		return
	}

	urlarr := strings.Split(strings.Trim(strings.Split(url, "?")[0], "/"), "/")
	data, handler := this.tree.FindRouter(strings.Split(url, "?")[0])
	if handler != nil {
		this.doController(data, urlarr, handler, w, r)
		return
	}

	log.ErrorTag(this, url+" do not find")

}
Exemplo n.º 3
0
func (this *Controller) Display(args ...string) {
	tpl := this.Template(args...)
	aolog.InfoTag(this, tpl)
	if _, err := os.Stat(tpl); err != nil {
		aolog.ErrorTag(this, "file "+tpl+" do not exist")
		return
	}

	t, err := template.ParseFiles(tpl)
	if err != nil {
		log.Println(err)
	}

	if len(this.UrlKey) < 2 {
		this.Data["url"] = ""
		this.Data["nspace"] = ""
	} else {
		this.Data["url"] = "/" + strings.Join(this.UrlKey[:len(this.UrlKey)-1], "/")
		this.Data["nspace"] = "/" + strings.Join(this.UrlKey[:len(this.UrlKey)-2], "/")
	}
	this.Data["res"] = this.Data["nspace"]
	t.Execute(this.w, this.Data)
}
Exemplo n.º 4
0
func (this *ControllerRegistor) doController(data, urlarr []string, h interface{}, w http.ResponseWriter, r *http.Request) {
	switch handler := h.(type) {
	case *Handler:
		reflectVal := reflect.ValueOf(handler.controller)
		handler.controller.Init(w, r, handler.controller, handler.method, data)
		if handler.controller.WillDid() {
			handler.controller.SetUrl(urlarr[:len(urlarr)-len(data)])
			if val := reflectVal.MethodByName(handler.method); val.IsValid() {
				val.Call([]reflect.Value{})
			} else {
				panic("'' method doesn't exist in the controller " + handler.method)
			}
		}
		handler.controller.Release()
		break
	case http.Handler:
		handler.ServeHTTP(w, r)
		break
	default:
		log.ErrorTag(this, h, " do not find")
	}

}