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") }
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) } }
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 }
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() }
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) }
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() }
func (this *UserModel) DoTest() { aolog.Info("DoTest") }
func (this *TestController) TestTpl() { aolog.Info(this.GetSession("user")) this.Data["name"] = "hello" this.Display() }