forked from golang/hotime
This commit is contained in:
parent
0219261dac
commit
4a0f8d9b88
@ -5,8 +5,8 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="">
|
||||
<change type="MOVED" beforePath="$PROJECT_DIR$/cachedb.go" afterPath="$PROJECT_DIR$/cache_db.go" />
|
||||
<change type="MOVED" beforePath="$PROJECT_DIR$/cachememory.go" afterPath="$PROJECT_DIR$/cache_memory.go" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/application.go" afterPath="$PROJECT_DIR$/application.go" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/context.go" afterPath="$PROJECT_DIR$/context.go" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="TRACKING_ENABLED" value="true" />
|
||||
@ -17,7 +17,79 @@
|
||||
</component>
|
||||
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
|
||||
<component name="FileEditorManager">
|
||||
<leaf />
|
||||
<leaf>
|
||||
<file leaf-file-name="application.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/application.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="142">
|
||||
<caret line="206" column="10" lean-forward="false" selection-start-line="206" selection-start-column="10" selection-end-line="206" selection-end-column="10" />
|
||||
<folding>
|
||||
<marker date="1503369750531" expanded="true" signature="164:222" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5062:5989" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5088:5304" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5215:5300" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5393:5656" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5473:5585" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5549:5581" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5616:5653" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5691:5725" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5808:5900" ph="{...}" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="context.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/context.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="170">
|
||||
<caret line="12" column="30" lean-forward="true" selection-start-line="12" selection-start-column="30" selection-end-line="12" selection-end-column="30" />
|
||||
<folding>
|
||||
<marker date="1503370865995" expanded="true" signature="880:935" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="880:1005" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="880:1081" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1011:1039" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1111:1262" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1138:1151" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1206:1219" ph="{...}" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="server.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://D:/app/go/src/net/http/server.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="-49">
|
||||
<caret line="89" column="5" lean-forward="false" selection-start-line="89" selection-start-column="5" selection-end-line="89" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="config.json" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/config/config.json">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="0">
|
||||
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="main.go" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/example/main.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="34">
|
||||
<caret line="2" column="7" lean-forward="true" selection-start-line="2" selection-start-column="7" selection-end-line="2" selection-end-column="7" />
|
||||
<folding>
|
||||
<element signature="e#14#101#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
@ -58,6 +130,7 @@
|
||||
<option value="$PROJECT_DIR$/var.go" />
|
||||
<option value="$PROJECT_DIR$/example/tpt/index.html" />
|
||||
<option value="$PROJECT_DIR$/example/main.go" />
|
||||
<option value="$PROJECT_DIR$/application.go" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@ -154,6 +227,20 @@
|
||||
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
|
||||
</PATH_ELEMENT>
|
||||
</PATH>
|
||||
<PATH>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="hotime" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="hotime" />
|
||||
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="config" />
|
||||
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
|
||||
</PATH_ELEMENT>
|
||||
</PATH>
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="Scratches" />
|
||||
@ -350,7 +437,7 @@
|
||||
<workItem from="1502674761674" duration="3300000" />
|
||||
<workItem from="1502760226287" duration="153000" />
|
||||
<workItem from="1502935911308" duration="1724000" />
|
||||
<workItem from="1503366689326" duration="52000" />
|
||||
<workItem from="1503366689326" duration="1383000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001">
|
||||
<created>1500458878821</created>
|
||||
@ -436,11 +523,18 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1502937437340</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="13" />
|
||||
<task id="LOCAL-00013" summary="demo">
|
||||
<created>1503366743140</created>
|
||||
<option name="number" value="00013" />
|
||||
<option name="presentableId" value="LOCAL-00013" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1503366743140</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="14" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="55931000" />
|
||||
<option name="totallyTimeSpent" value="57262000" />
|
||||
</component>
|
||||
<component name="TodoView">
|
||||
<todo-panel id="selected-file">
|
||||
@ -454,12 +548,12 @@
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="55" y="-8" width="1873" height="1096" extended-state="6" />
|
||||
<layout>
|
||||
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.30446774" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.30446774" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
|
||||
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.63343716" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917964" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32917964" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24972437" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32846716" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
|
||||
@ -495,23 +589,6 @@
|
||||
<watches-manager />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/func.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="595">
|
||||
<caret line="46" column="12" lean-forward="false" selection-start-line="46" selection-start-column="12" selection-end-line="46" selection-end-column="12" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/var.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="408">
|
||||
<caret line="24" column="2" lean-forward="true" selection-start-line="24" selection-start-column="2" selection-end-line="24" selection-end-column="2" />
|
||||
<folding>
|
||||
<marker date="1502936006492" expanded="true" signature="821:829" ph="{...}" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/map.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="323">
|
||||
@ -725,14 +802,6 @@
|
||||
<entry file="file://$PROJECT_DIR$/memorycache.go" />
|
||||
<entry file="file://$PROJECT_DIR$/dbcache.go" />
|
||||
<entry file="file://$PROJECT_DIR$/app.go" />
|
||||
<entry file="file://$PROJECT_DIR$/application.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="238">
|
||||
<caret line="24" column="25" lean-forward="true" selection-start-line="24" selection-start-column="25" selection-end-line="24" selection-end-column="25" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/cache_db.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="170">
|
||||
@ -757,14 +826,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/context.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="138">
|
||||
<caret line="34" column="20" lean-forward="false" selection-start-line="34" selection-start-column="20" selection-end-line="34" selection-end-column="20" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/db.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="68">
|
||||
@ -785,6 +846,7 @@
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="903">
|
||||
<caret line="136" column="1" lean-forward="false" selection-start-line="136" selection-start-column="1" selection-end-line="136" selection-end-column="1" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -806,6 +868,7 @@
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<caret line="6" column="0" lean-forward="false" selection-start-line="6" selection-start-column="0" selection-end-line="6" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -823,6 +886,7 @@
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="799">
|
||||
<caret line="48" column="0" lean-forward="false" selection-start-line="48" selection-start-column="0" selection-end-line="48" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -830,6 +894,7 @@
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="-83">
|
||||
<caret line="17" column="67" lean-forward="false" selection-start-line="17" selection-start-column="67" selection-end-line="17" selection-end-column="67" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -855,10 +920,61 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/application.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="142">
|
||||
<caret line="206" column="10" lean-forward="false" selection-start-line="206" selection-start-column="10" selection-end-line="206" selection-end-column="10" />
|
||||
<folding>
|
||||
<marker date="1503369750531" expanded="true" signature="164:222" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5062:5989" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5088:5304" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5215:5300" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5393:5656" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5473:5585" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5549:5581" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5616:5653" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5691:5725" ph="{...}" />
|
||||
<marker date="1503369750531" expanded="true" signature="5808:5900" ph="{...}" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/context.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="170">
|
||||
<caret line="12" column="30" lean-forward="true" selection-start-line="12" selection-start-column="30" selection-end-line="12" selection-end-column="30" />
|
||||
<folding>
|
||||
<marker date="1503370865995" expanded="true" signature="880:935" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="880:1005" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="880:1081" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1011:1039" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1111:1262" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1138:1151" ph="{...}" />
|
||||
<marker date="1503370865995" expanded="true" signature="1206:1219" ph="{...}" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://D:/app/go/src/net/http/server.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="-49">
|
||||
<caret line="89" column="5" lean-forward="false" selection-start-line="89" selection-start-column="5" selection-end-line="89" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/config/config.json">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="0">
|
||||
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/main.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="153">
|
||||
<caret line="54" column="53" lean-forward="true" selection-start-line="54" selection-start-column="53" selection-end-line="54" selection-end-column="53" />
|
||||
<state relative-caret-position="34">
|
||||
<caret line="2" column="7" lean-forward="true" selection-start-line="2" selection-start-column="7" selection-end-line="2" selection-end-column="7" />
|
||||
<folding>
|
||||
<element signature="e#14#101#0" expanded="true" />
|
||||
</folding>
|
||||
|
106
application.go
106
application.go
@ -16,7 +16,7 @@ type Application struct {
|
||||
Router
|
||||
Error
|
||||
Port string //端口号
|
||||
connectListener func(context Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
||||
connectListener []func(this *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
||||
connectDbFunc func(err ...*Error) *sql.DB
|
||||
configPath string
|
||||
Config Map
|
||||
@ -142,8 +142,8 @@ func (this *Application) SetConfig(configPath ...string) {
|
||||
}
|
||||
|
||||
//连接判断,返回true继续传输至控制层,false则停止传输
|
||||
func (this *Application) SetConnectListener(lis func(context Context) bool) {
|
||||
this.connectListener = lis
|
||||
func (this *Application) SetConnectListener(lis func(this *Context) bool) {
|
||||
this.connectListener = append(this.connectListener, lis)
|
||||
}
|
||||
|
||||
//网络错误
|
||||
@ -151,14 +151,13 @@ func (this *Application) session(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
//访问
|
||||
func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
q := strings.Index(req.RequestURI, "?")
|
||||
//序列化链接
|
||||
func (this *Application) urlSer(url string) (string, []string) {
|
||||
q := strings.Index(url, "?")
|
||||
if q == -1 {
|
||||
q = len(req.RequestURI)
|
||||
q = len(url)
|
||||
}
|
||||
o := Substr(req.RequestURI, 0, q)
|
||||
o := Substr(url, 0, q)
|
||||
|
||||
r := strings.SplitN(o, "/", -1)
|
||||
|
||||
@ -169,50 +168,61 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
s = append(s, r[i])
|
||||
}
|
||||
}
|
||||
return o, s
|
||||
}
|
||||
|
||||
//访问
|
||||
func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
o, s := this.urlSer(req.RequestURI)
|
||||
//获取cookie
|
||||
// 如果cookie存在直接将sessionId赋值为cookie.Value
|
||||
// 如果cookie不存在就查找传入的参数中是否有token
|
||||
// 如果token不存在就生成随机的sessionId
|
||||
// 如果token存在就判断token是否在Session中有保存
|
||||
// 如果有取出token并复制给cookie
|
||||
// 没有保存就生成随机的session
|
||||
cookie, err := req.Cookie((Config["sessionName"]).(string))
|
||||
sessionId := Md5(strconv.Itoa(Rand(10)))
|
||||
token := req.FormValue("token")
|
||||
//isFirst:=false
|
||||
if err != nil || (len(token) == 32 && cookie.Value != token) {
|
||||
if len(token) == 32 {
|
||||
sessionId = token
|
||||
}
|
||||
//else{
|
||||
// isFirst=true;
|
||||
//}
|
||||
http.SetCookie(w, &http.Cookie{Name: Config["sessionName"].(string), Value: sessionId, Path: "/"})
|
||||
} else {
|
||||
sessionId = cookie.Value
|
||||
}
|
||||
|
||||
//访问实例
|
||||
context := Context{SessionIns: SessionIns{SessionId: sessionId,
|
||||
LongCache: this.sessionLong,
|
||||
ShortCache: this.sessionShort,
|
||||
},
|
||||
CacheIns: this.CacheIns,
|
||||
Resp: w, Req: req, Application: this, RouterString: s, Config: this.Config, Db: &this.Db, HandlerStr: req.RequestURI}
|
||||
|
||||
//访问拦截true继续false暂停
|
||||
connectListenerLen:=len(this.connectListener)
|
||||
if connectListenerLen!= 0 {
|
||||
for i := 0; i < connectListenerLen; i++ {
|
||||
|
||||
if !this.connectListener[i](&context) {
|
||||
context.View()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
o, s = this.urlSer(context.HandlerStr)
|
||||
context.RouterString = s
|
||||
//接口服务
|
||||
if len(s) == 3 {
|
||||
//如果满足规则则路由到对应控制器去
|
||||
if this.Router[s[0]] != nil && this.Router[s[0]][s[1]] != nil && this.Router[s[0]][s[1]][s[2]] != nil {
|
||||
|
||||
//获取cookie
|
||||
// 如果cookie存在直接将sessionId赋值为cookie.Value
|
||||
// 如果cookie不存在就查找传入的参数中是否有token
|
||||
// 如果token不存在就生成随机的sessionId
|
||||
// 如果token存在就判断token是否在Session中有保存
|
||||
// 如果有取出token并复制给cookie
|
||||
// 没有保存就生成随机的session
|
||||
cookie, err := req.Cookie((Config["sessionName"]).(string))
|
||||
sessionId := Md5(strconv.Itoa(Rand(10)))
|
||||
token := req.FormValue("token")
|
||||
//isFirst:=false
|
||||
if err != nil || (len(token) == 32 && cookie.Value != token) {
|
||||
if len(token) == 32 {
|
||||
sessionId = token
|
||||
}
|
||||
//else{
|
||||
// isFirst=true;
|
||||
//}
|
||||
http.SetCookie(w, &http.Cookie{Name: Config["sessionName"].(string), Value: sessionId, Path: "/"})
|
||||
} else {
|
||||
sessionId = cookie.Value
|
||||
}
|
||||
|
||||
//访问实例
|
||||
context := Context{SessionIns: SessionIns{SessionId: sessionId,
|
||||
LongCache: this.sessionLong,
|
||||
ShortCache: this.sessionShort,
|
||||
},
|
||||
CacheIns: this.CacheIns,
|
||||
Resp: w, Req: req, Application: this, RouterString: s, Config: this.Config, Db: &this.Db}
|
||||
|
||||
//访问拦截
|
||||
if this.connectListener != nil {
|
||||
if !this.connectListener(context) {
|
||||
context.View()
|
||||
return
|
||||
}
|
||||
}
|
||||
//控制层
|
||||
this.Router[s[0]][s[1]][s[2]](&context)
|
||||
context.View()
|
||||
|
18
config/config.json
Normal file
18
config/config.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"cacheLongTime": 2592000,
|
||||
"cacheShortTime": 7200,
|
||||
"dbHost": "127.0.0.1",
|
||||
"dbName": "test",
|
||||
"dbPort": "3306",
|
||||
"dbPwd": "root",
|
||||
"dbUser": "root",
|
||||
"defFile": [
|
||||
"index.html",
|
||||
"index.htm"
|
||||
],
|
||||
"error": {},
|
||||
"logLevel": 0,
|
||||
"port": "80",
|
||||
"sessionName": "HOTIME",
|
||||
"tpt": "tpt"
|
||||
}
|
23
context.go
23
context.go
@ -2,9 +2,9 @@ package hotime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
@ -12,13 +12,14 @@ type Context struct {
|
||||
tag int64
|
||||
Resp http.ResponseWriter
|
||||
Req *http.Request
|
||||
Application *Application
|
||||
Application *Application
|
||||
RouterString []string
|
||||
Config Map
|
||||
Db *HoTimeDB
|
||||
resp Map
|
||||
RespData Map
|
||||
CacheIns
|
||||
SessionIns
|
||||
HandlerStr string //复写请求url
|
||||
}
|
||||
|
||||
//唯一标志
|
||||
@ -33,8 +34,8 @@ func (this *Context) GetTag() int64 {
|
||||
//唯一标志
|
||||
func (this *Context) Mtd(router [3]string) Map {
|
||||
this.Application.Router[router[0]][router[1]][router[2]](this)
|
||||
d := this.resp
|
||||
this.resp = nil
|
||||
d := this.RespData
|
||||
this.RespData = nil
|
||||
return d
|
||||
}
|
||||
|
||||
@ -45,8 +46,8 @@ func (this *Context) Display(statu int, data interface{}) {
|
||||
if statu != 0 {
|
||||
temp := Map{}
|
||||
|
||||
tpe:=this.Config.GetMap("error").GetString(ObjToStr(statu))
|
||||
if tpe==""{
|
||||
tpe := this.Config.GetMap("error").GetString(ObjToStr(statu))
|
||||
if tpe == "" {
|
||||
this.LastErr.SetError(errors.New("找不到对应的错误码"))
|
||||
}
|
||||
|
||||
@ -57,19 +58,19 @@ func (this *Context) Display(statu int, data interface{}) {
|
||||
resp["result"] = data
|
||||
}
|
||||
|
||||
this.resp = resp
|
||||
this.RespData = resp
|
||||
|
||||
//this.Data=d;
|
||||
}
|
||||
|
||||
func (this *Context) View() {
|
||||
if this.resp == nil {
|
||||
if this.RespData == nil {
|
||||
return
|
||||
}
|
||||
d, err := json.Marshal(this.resp)
|
||||
d, err := json.Marshal(this.RespData)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
this.resp = nil
|
||||
this.RespData = nil
|
||||
this.Resp.Write(d)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user