示例#1
0
文件: web_demo.go 项目: artwebs/aogo
func (this *TestController) Index() {
	// model := web.D(new(TestModel))
	model := &UserModel{}
	// model.DBPrifix = "PG"
	// model := NewPgUser()
	web.D(model, "PG")
	// aolog.Info(model.Insert(map[string]interface{}{"name": "test"}))
	// aolog.Info(model.Where("id=?", 1).Update(map[string]interface{}{"name": "test1"}))
	// aolog.Info(model.Where("id=?",16).Delete())
	// aolog.Info(model.Query("select * from user"))
	// aolog.Info(model.Where("id=?",1).Find())
	// aolog.Info(model.Total())
	// aolog.Info(model.Where("id=?",1).Total())
	aolog.Info(model.Order("id desc").Select())
	if user, ok := this.Form["user"]; ok {
		this.SetSession("user", user)
	}
	aolog.Info(this.Data)
	tmp := make(map[string]interface{})
	tmp["a"] = 1
	tmp["b"] = "jom"
	this.WriteJson(tmp)
	// this.WriteString("artwebs")
	// this.WriteString("artwebs1")
}
示例#2
0
文件: web.go 项目: artwebs/aogo
func Run() {
	for _, item := range register.namespaces {
		HandleFile(item+"/css", ViewsPath)
		HandleFile(item+"/js", ViewsPath)
		HandleFile(item+"/images", ViewsPath)
	}
	aolog.Info(register.tree)
	conn := &http.Server{Addr: HttpAddress + ":" + strconv.Itoa(HttpPort), Handler: register, ReadTimeout: 5 * time.Second}
	aolog.Info("server " + HttpAddress + ":" + strconv.Itoa(HttpPort) + " started")
	err := conn.ListenAndServe()
	if err != nil {
		log.Fatal(err)
	}

}
示例#3
0
文件: driver.go 项目: artwebs/aogo
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
}
示例#4
0
文件: main.go 项目: artwebs/aogo
func main() {
	version := flag.Bool("version", false, "--version")

	flag.Parse()
	log.Info("version:v1.0.0")
	if *version {
		return
	}
	reload()
	web.Router("/", &IndexController{}, "Index")
	web.Run()

}
示例#5
0
文件: main.go 项目: artwebs/aogo
func reload() {
	routerTree = web.NewRouterTree()
	sstr := readSimple("session.json")
	if sstr != "" {
		json.Unmarshal([]byte(sstr), &sessions)
	}
	log.Info("session", sessions)
	reg, _ := regexp.Compile("^[^rw_]\\w.+\\.json$")
	// 遍历目录
	filepath.Walk("./router",
		func(path string, f os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			if f.IsDir() {
				return nil
			}
			// 匹配目录
			matched := reg.MatchString(f.Name())
			if matched {
				log.Info("reload", path)
				sstr = readSimple(path)
				temp := make(map[string]*Router)
				if sstr != "" {
					json.Unmarshal([]byte(sstr), &temp)
					for k, v := range temp {
						if strings.HasPrefix(k, "/") {
							routerTree.AddRouter(k, v)
						} else {
							routerTree.AddRouter("/"+strings.TrimSuffix(f.Name(), ".json")+"/"+k, v)
						}
					}
				}
			}
			return nil
		})
	log.Info("routerTree", routerTree)
}
示例#6
0
文件: main.go 项目: artwebs/aogo
func main() {
	version := flag.Bool("version", false, "--version")
	flag.Parse()
	log.Info("version:v1.0.0")
	if *version {
		return
	}
	sessions = make(map[string]*Session)

	reload()
	web.Router("/", &IndexController{}, "Index")
	web.HandleFunc("/reload", GOReload)
	web.Run()

}
示例#7
0
文件: web_demo.go 项目: artwebs/aogo
func (this *UserModel) DoTest() {
	aolog.Info("DoTest")

}
示例#8
0
文件: web_demo.go 项目: artwebs/aogo
func (this *TestController) TestTpl() {
	aolog.Info(this.GetSession("user"))
	this.Data["name"] = "hello"
	this.Display()
}