This commit is contained in:
hoteas 2017-08-22 08:24:55 +00:00
parent 0219261dac
commit 4a0f8d9b88
4 changed files with 247 additions and 102 deletions

202
.idea/workspace.xml generated
View File

@ -5,8 +5,8 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment=""> <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="MODIFICATION" beforePath="$PROJECT_DIR$/application.go" afterPath="$PROJECT_DIR$/application.go" />
<change type="MOVED" beforePath="$PROJECT_DIR$/cachememory.go" afterPath="$PROJECT_DIR$/cache_memory.go" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/context.go" afterPath="$PROJECT_DIR$/context.go" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" /> <option name="TRACKING_ENABLED" value="true" />
@ -17,7 +17,79 @@
</component> </component>
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" /> <component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
<component name="FileEditorManager"> <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>
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
@ -58,6 +130,7 @@
<option value="$PROJECT_DIR$/var.go" /> <option value="$PROJECT_DIR$/var.go" />
<option value="$PROJECT_DIR$/example/tpt/index.html" /> <option value="$PROJECT_DIR$/example/tpt/index.html" />
<option value="$PROJECT_DIR$/example/main.go" /> <option value="$PROJECT_DIR$/example/main.go" />
<option value="$PROJECT_DIR$/application.go" />
</list> </list>
</option> </option>
</component> </component>
@ -154,6 +227,20 @@
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" /> <option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT> </PATH_ELEMENT>
</PATH> </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> </subPane>
</pane> </pane>
<pane id="Scratches" /> <pane id="Scratches" />
@ -350,7 +437,7 @@
<workItem from="1502674761674" duration="3300000" /> <workItem from="1502674761674" duration="3300000" />
<workItem from="1502760226287" duration="153000" /> <workItem from="1502760226287" duration="153000" />
<workItem from="1502935911308" duration="1724000" /> <workItem from="1502935911308" duration="1724000" />
<workItem from="1503366689326" duration="52000" /> <workItem from="1503366689326" duration="1383000" />
</task> </task>
<task id="LOCAL-00001"> <task id="LOCAL-00001">
<created>1500458878821</created> <created>1500458878821</created>
@ -436,11 +523,18 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1502937437340</updated> <updated>1502937437340</updated>
</task> </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 /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="55931000" /> <option name="totallyTimeSpent" value="57262000" />
</component> </component>
<component name="TodoView"> <component name="TodoView">
<todo-panel id="selected-file"> <todo-panel id="selected-file">
@ -454,12 +548,12 @@
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="55" y="-8" width="1873" height="1096" extended-state="6" /> <frame x="55" y="-8" width="1873" height="1096" extended-state="6" />
<layout> <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="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="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="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="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="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="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" /> <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 /> <watches-manager />
</component> </component>
<component name="editorHistoryManager"> <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"> <entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323"> <state relative-caret-position="323">
@ -725,14 +802,6 @@
<entry file="file://$PROJECT_DIR$/memorycache.go" /> <entry file="file://$PROJECT_DIR$/memorycache.go" />
<entry file="file://$PROJECT_DIR$/dbcache.go" /> <entry file="file://$PROJECT_DIR$/dbcache.go" />
<entry file="file://$PROJECT_DIR$/app.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"> <entry file="file://$PROJECT_DIR$/cache_db.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="170"> <state relative-caret-position="170">
@ -757,14 +826,6 @@
</state> </state>
</provider> </provider>
</entry> </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"> <entry file="file://$PROJECT_DIR$/db.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68"> <state relative-caret-position="68">
@ -785,6 +846,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="903"> <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" /> <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> </state>
</provider> </provider>
</entry> </entry>
@ -806,6 +868,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102"> <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" /> <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> </state>
</provider> </provider>
</entry> </entry>
@ -823,6 +886,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="799"> <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" /> <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> </state>
</provider> </provider>
</entry> </entry>
@ -830,6 +894,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-83"> <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" /> <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> </state>
</provider> </provider>
</entry> </entry>
@ -855,10 +920,61 @@
</state> </state>
</provider> </provider>
</entry> </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"> <entry file="file://$PROJECT_DIR$/example/main.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153"> <state relative-caret-position="34">
<caret line="54" column="53" lean-forward="true" selection-start-line="54" selection-start-column="53" selection-end-line="54" selection-end-column="53" /> <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> <folding>
<element signature="e#14#101#0" expanded="true" /> <element signature="e#14#101#0" expanded="true" />
</folding> </folding>

View File

@ -16,7 +16,7 @@ type Application struct {
Router Router
Error Error
Port string //端口号 Port string //端口号
connectListener func(context Context) bool //所有的访问监听,true按原计划继续使用false表示有监听器处理 connectListener []func(this *Context) bool //所有的访问监听,true按原计划继续使用false表示有监听器处理
connectDbFunc func(err ...*Error) *sql.DB connectDbFunc func(err ...*Error) *sql.DB
configPath string configPath string
Config Map Config Map
@ -142,8 +142,8 @@ func (this *Application) SetConfig(configPath ...string) {
} }
//连接判断,返回true继续传输至控制层false则停止传输 //连接判断,返回true继续传输至控制层false则停止传输
func (this *Application) SetConnectListener(lis func(context Context) bool) { func (this *Application) SetConnectListener(lis func(this *Context) bool) {
this.connectListener = lis 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) { func (this *Application) urlSer(url string) (string, []string) {
q := strings.Index(url, "?")
q := strings.Index(req.RequestURI, "?")
if q == -1 { 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) r := strings.SplitN(o, "/", -1)
@ -169,12 +168,13 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
s = append(s, r[i]) s = append(s, r[i])
} }
} }
return o, s
}
//接口服务 //访问
if len(s) == 3 { func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
//如果满足规则则路由到对应控制器去
if this.Router[s[0]] != nil && this.Router[s[0]][s[1]] != nil && this.Router[s[0]][s[1]][s[2]] != nil {
o, s := this.urlSer(req.RequestURI)
//获取cookie //获取cookie
// 如果cookie存在直接将sessionId赋值为cookie.Value // 如果cookie存在直接将sessionId赋值为cookie.Value
// 如果cookie不存在就查找传入的参数中是否有token // 如果cookie不存在就查找传入的参数中是否有token
@ -204,15 +204,25 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
ShortCache: this.sessionShort, ShortCache: this.sessionShort,
}, },
CacheIns: this.CacheIns, CacheIns: this.CacheIns,
Resp: w, Req: req, Application: this, RouterString: s, Config: this.Config, Db: &this.Db} Resp: w, Req: req, Application: this, RouterString: s, Config: this.Config, Db: &this.Db, HandlerStr: req.RequestURI}
//访问拦截 //访问拦截true继续false暂停
if this.connectListener != nil { connectListenerLen:=len(this.connectListener)
if !this.connectListener(context) { if connectListenerLen!= 0 {
for i := 0; i < connectListenerLen; i++ {
if !this.connectListener[i](&context) {
context.View() context.View()
return 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 {
//控制层 //控制层
this.Router[s[0]][s[1]][s[2]](&context) this.Router[s[0]][s[1]][s[2]](&context)
context.View() context.View()

18
config/config.json Normal file
View 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"
}

View File

@ -2,9 +2,9 @@ package hotime
import ( import (
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"time" "time"
"errors"
) )
type Context struct { type Context struct {
@ -16,9 +16,10 @@ type Context struct {
RouterString []string RouterString []string
Config Map Config Map
Db *HoTimeDB Db *HoTimeDB
resp Map RespData Map
CacheIns CacheIns
SessionIns SessionIns
HandlerStr string //复写请求url
} }
//唯一标志 //唯一标志
@ -33,8 +34,8 @@ func (this *Context) GetTag() int64 {
//唯一标志 //唯一标志
func (this *Context) Mtd(router [3]string) Map { func (this *Context) Mtd(router [3]string) Map {
this.Application.Router[router[0]][router[1]][router[2]](this) this.Application.Router[router[0]][router[1]][router[2]](this)
d := this.resp d := this.RespData
this.resp = nil this.RespData = nil
return d return d
} }
@ -57,19 +58,19 @@ func (this *Context) Display(statu int, data interface{}) {
resp["result"] = data resp["result"] = data
} }
this.resp = resp this.RespData = resp
//this.Data=d; //this.Data=d;
} }
func (this *Context) View() { func (this *Context) View() {
if this.resp == nil { if this.RespData == nil {
return return
} }
d, err := json.Marshal(this.resp) d, err := json.Marshal(this.RespData)
if err != nil { if err != nil {
return return
} }
this.resp = nil this.RespData = nil
this.Resp.Write(d) this.Resp.Write(d)
} }