diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 008c91f..c3310c0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,9 +5,16 @@
+
+
+
+
+
+
+
@@ -19,90 +26,117 @@
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -127,17 +161,22 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -222,118 +261,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -603,7 +530,7 @@
-
+
1500458878821
@@ -703,11 +630,18 @@
1503393349195
-
+
+ 1503452484959
+
+
+
+ 1503452484959
+
+
-
+
@@ -720,18 +654,17 @@
-
-
+
-
+
-
+
@@ -758,19 +691,19 @@
-
+
+
+ file://$PROJECT_DIR$/example/main.go
+ 16
+
+
+
+
+
-
-
-
-
-
-
-
-
@@ -969,94 +902,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1082,32 +927,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1116,23 +935,160 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/base_context.go b/base_context.go
new file mode 100644
index 0000000..23ccc8f
--- /dev/null
+++ b/base_context.go
@@ -0,0 +1,17 @@
+package hotime
+
+import "time"
+
+type baseContext struct {
+ Error
+ tag int64
+}
+
+//唯一标志
+func (this *baseContext) GetTag() int64 {
+
+ if this.tag == int64(0) {
+ this.tag = time.Now().UnixNano()
+ }
+ return this.tag
+}
diff --git a/cache_db.go b/cache_db.go
index 45a5e9e..f0ba7bb 100644
--- a/cache_db.go
+++ b/cache_db.go
@@ -8,7 +8,7 @@ import (
type CacheDb struct {
Time int64
Db *HoTimeDB
- Error
+ baseContext
isInit bool
}
diff --git a/cache_memory.go b/cache_memory.go
index 9333da7..014830b 100644
--- a/cache_memory.go
+++ b/cache_memory.go
@@ -7,13 +7,13 @@ import (
type CacheMemory struct {
Time int64
Map
- Error
+ baseContext
}
//获取Cache键只能为string类型
func (this *CacheMemory) get(key string) interface{} {
this.Error.SetError(nil)
- if this.Map[key]==nil{
+ if this.Map[key] == nil {
return nil
}
data := this.Map.Get(key, &this.Error).(cacheData)
@@ -43,10 +43,10 @@ func (this *CacheMemory) set(key string, value interface{}, time int64) {
data.time = time
data.data = value
- if this.Map==nil{
- this.Map=Map{}
+ if this.Map == nil {
+ this.Map = Map{}
}
- this.Map.Put(key,data)
+ this.Map.Put(key, data)
}
func (this *CacheMemory) delete(key string) {
diff --git a/config/config.json b/config/config.json
index 3d4ee02..efbdac0 100644
--- a/config/config.json
+++ b/config/config.json
@@ -12,7 +12,7 @@
],
"error": {},
"logLevel": 0,
- "port": "80",
+ "port": "8080",
"sessionName": "HOTIME",
"tpt": "tpt"
}
\ No newline at end of file
diff --git a/context.go b/context.go
index f49fae7..a72cd24 100644
--- a/context.go
+++ b/context.go
@@ -4,12 +4,10 @@ import (
"encoding/json"
"errors"
"net/http"
- "time"
)
type Context struct {
- LastErr Error
- tag int64
+ baseContext
Resp http.ResponseWriter
Req *http.Request
Application *Application
@@ -22,14 +20,6 @@ type Context struct {
HandlerStr string //复写请求url
}
-//唯一标志
-func (this *Context) GetTag() int64 {
-
- if this.tag == int64(0) {
- this.tag = time.Now().UnixNano()
- }
- return this.tag
-}
//唯一标志
func (this *Context) Mtd(router [3]string) Map {
diff --git a/db.go b/db.go
index cd459da..d95072d 100644
--- a/db.go
+++ b/db.go
@@ -11,12 +11,13 @@ import (
type HoTimeDB struct {
*sql.DB
- Context
+ baseContext
+
Cached bool
LastQuery string
LastData []interface{}
ConnectFunc func(err ...*Error) *sql.DB
- //LastErr Error
+ LastErr Error
limit Slice
Tx *sql.Tx //事务对象
@@ -29,11 +30,11 @@ func (this *HoTimeDB) SetConnect(connect func(err ...*Error) *sql.DB, err ...*Er
}
//事务,如果action返回true则执行成功;false则回滚
-func (this *HoTimeDB) Action(action func() bool) Error {
+func (this *HoTimeDB) Action(action func() bool) bool {
tx, err := this.DB.Begin()
if err != nil {
this.LastErr.SetError(err)
- return this.LastErr
+ return false
}
this.Tx = tx
@@ -42,12 +43,12 @@ func (this *HoTimeDB) Action(action func() bool) Error {
if !result {
this.Tx.Rollback()
this.Tx = nil
- return nil
+ return true
}
this.Tx.Commit()
this.Tx = nil
- return nil
+ return true
}
func (this *HoTimeDB) InitDb(err ...*Error) Error {
diff --git a/example/main.go b/example/main.go
index fce8dd9..d6b1789 100644
--- a/example/main.go
+++ b/example/main.go
@@ -49,7 +49,11 @@ func main() {
"app": hotime.Proj{
"index": hotime.Ctr{
"test": func(this *hotime.Context) {
+ fmt.Println(this.Db.GetTag())
+ this.Db.Action(func() bool {
+ return true
+ })
this.Display(0, "chenggong")
},
"websocket": func(this *hotime.Context) {
diff --git a/obj.go b/obj.go
index 56ef7f1..f9efea8 100644
--- a/obj.go
+++ b/obj.go
@@ -3,7 +3,7 @@ package hotime
//对象封装方便取用
type Obj struct {
Data interface{}
- Error
+ baseContext
}
func (this *Obj) Put(data interface{}) {
diff --git a/session.go b/session.go
index 23ed0cf..ab6170e 100644
--- a/session.go
+++ b/session.go
@@ -6,7 +6,7 @@ type SessionIns struct {
LongCache CacheIns
SessionId string
Map
- Error
+ baseContext
}
func (this *SessionIns) set() {