diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 3485330..704e39e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,7 +7,6 @@
-
@@ -46,7 +45,7 @@
-
+
@@ -58,13 +57,13 @@
-
+
-
-
+
+
-
+
@@ -450,7 +449,7 @@
-
+
1500458878821
@@ -606,11 +605,18 @@
1504579259295
-
+
+ 1504580135665
+
+
+
+ 1504580135666
+
+
-
+
@@ -938,7 +944,7 @@
-
+
@@ -1007,16 +1013,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1027,5 +1023,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/example/main.go b/example/main.go
index c7de1a7..90b0591 100644
--- a/example/main.go
+++ b/example/main.go
@@ -1,54 +1,41 @@
package main
import (
-
+ "database/sql"
+ "fmt"
_ "github.com/go-sql-driver/mysql"
"go.hoteas.com/hotime"
- "time"
- //"fmt"
+ "golang.org/x/net/websocket"
)
func main() {
- a:=hotime.Map{}
- a.Put("x",1)
- for i:=0;i<30 ;i++ {
- go func() {
- for j:=0;j<30 ;j++ {
- if j/2==0{
- hotime.SafeMutex("test", func() interface{} {
+ appIns := hotime.Application{}
+ i := 0
- a.Put("x","1")
+ appIns.SetConnectListener(func(context *hotime.Context) bool {
+ fmt.Println(i)
+ i++
+ //this.HandlerStr = "/test.html"
+ return true
+ })
+ //手动模式,
+ appIns.SetConfig()
+ appIns.SetConnectDB(func(err ...*hotime.Error) *sql.DB {
+ query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") +
+ "@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8"
+ DB, e := sql.Open("mysql", query)
+ if e != nil && len(err) != 0 {
+ err[0].SetError(e)
+ }
+ return DB
+ })
+ appIns.SetSession(hotime.CacheIns(&hotime.CacheMemory{}), hotime.CacheIns(&hotime.CacheDb{Db: &appIns.Db, Time: appIns.Config.GetInt64("cacheTime")}))
+ appIns.SetCache(hotime.CacheIns(&hotime.CacheMemory{}))
- return nil
- })
- }else {
- //fmt.Println(a.GetInt64("x"))
- a.Delete("x")
- }
-
- }
- }()
-
-
- }
-
- time.Sleep(time.Second*5)
-
- //appIns := hotime.Application{}
- //i := 0
- //
- //appIns.SetConnectListener(func(context *hotime.Context) bool {
- // fmt.Println(i)
- // i++
- // //this.HandlerStr = "/test.html"
- // return true
- //})
- //
- ////手动模式,
- //appIns.SetConfig()
- //appIns.SetConnectDB(func(err ...*hotime.Error) *sql.DB {
+ //快捷模式
+ //appIns.SetDefault(func(err ...*hotime.Error) *sql.DB {
// query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") +
// "@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8"
// DB, e := sql.Open("mysql", query)
@@ -57,55 +44,42 @@ func main() {
// }
// return DB
//})
- //appIns.SetSession(hotime.CacheIns(&hotime.CacheMemory{}), hotime.CacheIns(&hotime.CacheDb{Db: &appIns.Db, Time: appIns.Config.GetInt64("cacheTime")}))
- //appIns.SetCache(hotime.CacheIns(&hotime.CacheMemory{}))
- //
- ////快捷模式
- ////appIns.SetDefault(func(err ...*hotime.Error) *sql.DB {
- //// query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") +
- //// "@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8"
- //// DB, e := sql.Open("mysql", query)
- //// if e != nil && len(err) != 0 {
- //// err[0].SetError(e)
- //// }
- //// return DB
- ////})
- //
- //appIns.Run(hotime.Router{
- // "app": hotime.Proj{
- // "index": hotime.Ctr{
- // "test": func(this *hotime.Context) {
- // fmt.Println(this.Db.GetTag())
- // x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
- //
- // db.Insert("user",hotime.Map{"unickname":"dasdas"})
- //
- // return true
- // })
- // this.Display(5, x)
- // },
- // "websocket": func(this *hotime.Context) {
- // hdler := websocket.Handler(func(ws *websocket.Conn) {
- // for true {
- // msg := make([]byte, 5120)
- // n, err := ws.Read(msg)
- //
- // if err != nil {
- // return
- // }
- // fmt.Printf("Receive: %s\n", msg[:n])
- //
- // send_msg := "[" + string(msg[:n]) + "]"
- // m, err := ws.Write([]byte(send_msg))
- // if err != nil {
- // return
- // }
- // fmt.Printf("Send: %s\n", msg[:m])
- // }
- // })
- // hdler.ServeHTTP(this.Resp, this.Req)
- // },
- // },
- // },
- //})
+
+ appIns.Run(hotime.Router{
+ "app": hotime.Proj{
+ "index": hotime.Ctr{
+ "test": func(this *hotime.Context) {
+ fmt.Println(this.Db.GetTag())
+ x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
+
+ db.Insert("user",hotime.Map{"unickname":"dasdas"})
+
+ return true
+ })
+ this.Display(5, x)
+ },
+ "websocket": func(this *hotime.Context) {
+ hdler := websocket.Handler(func(ws *websocket.Conn) {
+ for true {
+ msg := make([]byte, 5120)
+ n, err := ws.Read(msg)
+
+ if err != nil {
+ return
+ }
+ fmt.Printf("Receive: %s\n", msg[:n])
+
+ send_msg := "[" + string(msg[:n]) + "]"
+ m, err := ws.Write([]byte(send_msg))
+ if err != nil {
+ return
+ }
+ fmt.Printf("Send: %s\n", msg[:m])
+ }
+ })
+ hdler.ServeHTTP(this.Resp, this.Req)
+ },
+ },
+ },
+ })
}