Exemplo n.º 1
0
func (this *Driver) QueryNoConn(s string, args ...interface{}) ([]map[string]string, error) {
	defer this.Reset()
	cacheKey := this.getCacheName(s, args...)
	if this.CacheObj != nil && this.CacheObj.IsExist(cacheKey) && this.isCache {
		aolog.InfoTag(this, " get "+cacheKey)
		result := []map[string]string{}
		rbyte, err := base64.StdEncoding.DecodeString(this.CacheObj.GetString(cacheKey))
		if err == nil {
			json.Unmarshal(rbyte, &result)
		}
		return result, nil
	}
	result := []map[string]string{}
	aolog.Info(s, args)
	rows, err := this.db.Query(s, args...)
	if err != nil {
		return result, err
	}
	columns, err := rows.Columns()
	if err != nil {
		return result, err
	}
	values := make([]sql.RawBytes, len(columns))
	scanArgs := make([]interface{}, len(values))
	for i := range values {
		scanArgs[i] = &values[i]
	}
	for rows.Next() {
		err = rows.Scan(scanArgs...)
		if err != nil {
			return result, err
		}
		row := map[string]string{}
		for i, col := range values {
			if col == nil {
				row[columns[i]] = "NULL"
			} else {
				row[columns[i]] = string(col)
			}
		}
		result = append(result, row)
	}
	if this.CacheObj != nil && this.isCache {
		aolog.InfoTag(this, " save "+cacheKey)
		rbyte, err := json.Marshal(result)
		if err == nil {
			aolog.InfoTag(this, this.CacheObj.Put(cacheKey, base64.StdEncoding.EncodeToString(rbyte), 600*time.Second))
		}

	}
	return result, nil
}
Exemplo n.º 2
0
func (this *Model) Init(args ...string) {
	var err error
	var dbPrifix, driverName, dataSourceName, tabPrifix string
	for i, v := range args {
		switch i {
		case 0:
			dbPrifix = v
		}
	}
	conf, err = InitAppConfig()
	if err == nil {
		driverName = conf.String(dbPrifix+"DataBase::driverName", "")
		dataSourceName = conf.String(dbPrifix+"DataBase::dataSourceName", "")
		tabPrifix = conf.String(dbPrifix+"DataBase::tabPrifix", "")
	} else {
		log.Fatalln("AppConfig init fail")
	}

	CobjName := conf.String("Cache::name", "")
	CobjConfig := conf.String("Cache::config", "")
	var Cobj *cache.Cache
	if CobjName != "" && CobjConfig != "" {
		Cobj, err = cache.NewCache(CobjName, CobjConfig)
	}
	aolog.InfoTag(this, "dataSourceName", dataSourceName)
	this.Drv = database.Drivers(driverName)
	this.Drv.Init(driverName, dataSourceName, tabPrifix)
	this.Drv.SetCache(Cobj)
	this.Drv.SetDBPrifix(dbPrifix)
}
Exemplo n.º 3
0
Arquivo: main.go Projeto: artwebs/aogo
func (this *IndexController) verfiySession(sin string) bool {
	for _, ss := range strings.Split(sin, ",") {
		s := strings.Split(ss, ":")
		if len(s) == 1 {
			if val, ok := sessions[s[0]]; ok {
				if this.GetSession(s[0]) != nil {
					log.InfoTag(this, this.GetSession(s[0]))
					if val.Verfiy != "" {
						if this.Form[val.Verfiy] != this.GetSession(s[0]) {
							this.Redirect(val.Fail)
							return false
						} else {
							continue
						}
					}
					cursession := (this.GetSession(s[0])).(map[string]interface{})
					for k, v := range cursession {
						if _, tok := this.Form[k]; tok {
							this.Form["_"+k] = v
						} else {
							this.Form[k] = v
						}
					}
					continue
				}
				this.Redirect(val.Fail)
				return false
			}
		}
	}

	return true
}
Exemplo n.º 4
0
Arquivo: main.go Projeto: artwebs/aogo
func (this *IndexController) doSession(sin string) {
	for _, ss := range strings.Split(sin, ",") {
		s := strings.Split(ss, ":")
		if len(s) < 2 {
			continue
		}

		switch s[1] {
		case "save":
			if val, ok := sessions[s[0]]; ok {
				data := (this.Data[val.Name]).(map[string]interface{})
				if (data["code"]).(float64) == 1 {
					log.InfoTag(this, "doSession save", data["result"])
					this.SetSession(s[0], data["result"])
				}
			}
			break
		case "delete":
			this.FlushSession()
			break
		default:

		}
	}
}
Exemplo n.º 5
0
func (this *Driver) ExecNoConn(sql string, args ...interface{}) (sql.Result, error) {
	defer this.Reset()
	aolog.InfoTag(this, sql, args)
	stmt, err := this.db.Prepare(sql)
	if err != nil {
		return nil, err
	}
	defer stmt.Close()
	return stmt.Exec(args...)
}
Exemplo n.º 6
0
func (this *Postgresql) QueryRowNoConn(s string, args ...interface{}) (map[string]string, error) {
	defer this.Reset()
	this.limit = "1"
	var result map[string]string
	s = this.addLimit(s)
	rows, err := this.QueryNoConn(s, args...)
	aolog.InfoTag(this, rows)
	if err != nil {
		aolog.InfoTag(this, err)
		return result, err
	}
	if len(rows) > 0 {
		result = rows[0]
	} else {
		result = map[string]string{}
	}
	return result, nil

}
Exemplo n.º 7
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
	log.InfoTag(this, "drv", this.Drv)
	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.º 8
0
Arquivo: main.go Projeto: artwebs/aogo
func (this *IndexController) Index() {
	this.isEncrypt = false
	log.InfoTag(this, this.UrlVal)
	this.parseQuery()
	if len(this.UrlVal) >= 1 {
		key := this.UrlVal[0]
		if val := reflect.ValueOf(this).MethodByName(key); val.IsValid() || key == strings.Title(key) {
			val.Call([]reflect.Value{})
		} else {
			this.Normal()
		}

	} else {
		this.WriteJson(data_error("非法请求,已经进行了记录"))
	}
}
Exemplo n.º 9
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.º 10
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.º 11
0
Arquivo: main.go Projeto: artwebs/aogo
func (this *IndexController) Index() {
	this.UrlKey = this.UrlVal[:]
	router := "/" + strings.Join(this.UrlKey, "/")
	_, obj := routerTree.FindRouter(router)
	if obj != nil {
		val := obj.(*Router)
		if !this.verfiySession(val.Session) {
			return
		}
		model := &DefaultModel{}
		web.D(model)
		if val.Data != nil {
			for key, value := range val.Data {
				switch value {
				case "SaveFile":
					file, err := this.SaveToFile("File", "")
					if err == nil {
						this.Data[key] = map[string]interface{}{"code": 1, "message": "上传成功", "result": file}
					} else {
						this.Data[key] = map[string]interface{}{"code": 0, "message": err, "result": ""}
					}

					break
				case "VerfiyCode":
					d := make([]byte, 4)
					s := utils.NewLen(4)
					ss := ""
					d = []byte(s)
					for v := range d {
						d[v] %= 10
						ss += strconv.FormatInt(int64(d[v]), 32)
					}
					this.SetSession(key, ss)
					this.WriteImage(utils.NewImage(d, 100, 40))
					return
				case "DownloadFile":
					log.InfoTag(this, "DownloadFile", strings.TrimPrefix(router, "/"))
					this.ServeFile(strings.TrimPrefix(router, "/"))
					return
				default:
					this.Data[key] = model.Aws(value, this.Form)
				}

			}
		}
		this.doSession(val.Session)
		tpl := router
		if val.Tpl != "" {
			tpl = val.Tpl
		}
		this.Data["req"] = this.Form
		if _, err := os.Stat(this.Template(tpl)); err == nil {
			this.Display(tpl)
		} else {
			this.WriteJson(this.Data)
		}

	} else {
		this.WriteString(router + " do not find!")
	}

}