管理端初步

This commit is contained in:
hoteas 2017-09-05 02:40:37 +00:00
parent 22e092daba
commit 822d9708e4
4 changed files with 324 additions and 233 deletions

View File

@ -6,9 +6,9 @@
<component name="ChangeListManager">
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/const.go" afterPath="$PROJECT_DIR$/const.go" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/error.go" afterPath="$PROJECT_DIR$/error.go" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/session.go" afterPath="$PROJECT_DIR$/session.go" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/config/config.json" afterPath="$PROJECT_DIR$/config/config.json" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/example/main.go" afterPath="$PROJECT_DIR$/example/main.go" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/map.go" afterPath="$PROJECT_DIR$/map.go" />
</list>
<ignored path=".idea/dataSources.local.xml" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -27,26 +27,6 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="error.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/error.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="11" column="19" lean-forward="false" selection-start-line="11" selection-start-column="19" selection-end-line="11" selection-end-column="19" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="type.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/type.go">
<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>
</file>
<file leaf-file-name="var.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/var.go">
<provider selected="true" editor-type-id="text-editor">
@ -60,8 +40,62 @@
<file leaf-file-name="const.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/const.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="17" column="22" lean-forward="false" selection-start-line="17" selection-start-column="4" selection-end-line="17" selection-end-column="22" />
<state relative-caret-position="153">
<caret line="9" column="13" lean-forward="false" selection-start-line="9" selection-start-column="4" selection-end-line="9" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="map.go" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="184">
<caret line="47" column="16" lean-forward="false" selection-start-line="47" selection-start-column="16" selection-end-line="47" selection-end-column="16" />
<folding>
<element signature="e#16#74#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="main.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="13" column="7" lean-forward="true" selection-start-line="13" selection-start-column="7" selection-end-line="13" selection-end-column="7" />
<folding>
<element signature="e#14#100#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="fd_mutex.go" pinned="false" current-in-tab="false">
<entry file="file://D:/app/go/src/internal/poll/fd_mutex.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="236" column="0" lean-forward="false" selection-start-line="236" selection-start-column="0" selection-end-line="236" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="objtoobj.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/objtoobj.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
<caret line="32" column="5" lean-forward="false" selection-start-line="32" selection-start-column="5" selection-end-line="32" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="context_base.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/context_base.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="0" lean-forward="false" selection-start-line="9" selection-start-column="0" selection-end-line="16" selection-end-column="1" />
<folding />
</state>
</provider>
@ -77,51 +111,21 @@
</provider>
</entry>
</file>
<file leaf-file-name="manage.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/manage/manage.go">
<file leaf-file-name="cache_db.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/cache_db.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="510">
<caret line="39" column="9" lean-forward="false" selection-start-line="39" selection-start-column="9" selection-end-line="39" selection-end-column="9" />
<state relative-caret-position="-289">
<caret line="10" column="15" lean-forward="false" selection-start-line="10" selection-start-column="15" selection-end-line="10" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="config.json" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/config/config.json">
<file leaf-file-name="cache_memory.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/cache_memory.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="17" column="1" lean-forward="true" selection-start-line="17" selection-start-column="1" selection-end-line="17" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="file.go" pinned="false" current-in-tab="false">
<entry file="file://D:/app/go/src/debug/plan9obj/file.go">
<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="file_test.go" pinned="false" current-in-tab="false">
<entry file="file://D:/app/go/src/debug/plan9obj/file_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="527">
<caret line="34" column="36" lean-forward="false" selection-start-line="34" selection-start-column="36" selection-end-line="34" selection-end-column="36" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="plan9obj.go" pinned="false" current-in-tab="false">
<entry file="file://D:/app/go/src/debug/plan9obj/plan9obj.go">
<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" />
<state relative-caret-position="816">
<caret line="92" column="1" lean-forward="true" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
<folding />
</state>
</provider>
@ -142,9 +146,11 @@
<find>limit</find>
<find>Ping</find>
<find>SESSION_TYPE</find>
<find>GetString</find>
</findStrings>
<replaceStrings>
<replace>MUTEX_SESSION_TYPE</replace>
<replace>GetTag</replace>
</replaceStrings>
</component>
<component name="IdeDocumentHistory">
@ -152,7 +158,6 @@
<list>
<option value="$PROJECT_DIR$/slice.go" />
<option value="$PROJECT_DIR$/objtoobj.go" />
<option value="$PROJECT_DIR$/map.go" />
<option value="$PROJECT_DIR$/controller.go" />
<option value="$PROJECT_DIR$/Config.go" />
<option value="$PROJECT_DIR$/config.go" />
@ -175,11 +180,12 @@
<option value="$PROJECT_DIR$/context.go" />
<option value="$PROJECT_DIR$/config/config.json" />
<option value="$PROJECT_DIR$/db.go" />
<option value="$PROJECT_DIR$/example/main.go" />
<option value="$PROJECT_DIR$/manage/manage.go" />
<option value="$PROJECT_DIR$/error.go" />
<option value="$PROJECT_DIR$/const.go" />
<option value="$PROJECT_DIR$/session.go" />
<option value="$PROJECT_DIR$/example/main.go" />
<option value="$PROJECT_DIR$/map.go" />
</list>
</option>
</component>
@ -223,8 +229,8 @@
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="External Libraries" />
<option name="myItemType" value="com.jetbrains.php.config.library.PhpExternalLibrariesNodePatcher$PatchedExternalLibrariesNode" />
<option name="myItemId" value="hotime" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
<PATH>
@ -236,6 +242,10 @@
<option name="myItemId" value="hotime" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="example" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
@ -441,7 +451,7 @@
<workItem from="1504252839700" duration="18000" />
<workItem from="1504488004086" duration="365000" />
<workItem from="1504488391347" duration="840000" />
<workItem from="1504575702799" duration="26000" />
<workItem from="1504575702799" duration="3525000" />
</task>
<task id="LOCAL-00001">
<created>1500458878821</created>
@ -583,11 +593,18 @@
<option name="project" value="LOCAL" />
<updated>1504168369028</updated>
</task>
<option name="localTasksCounter" value="21" />
<task id="LOCAL-00021" summary="管理端初步">
<created>1504575745842</created>
<option name="number" value="00021" />
<option name="presentableId" value="LOCAL-00021" />
<option name="project" value="LOCAL" />
<updated>1504575745842</updated>
</task>
<option name="localTasksCounter" value="22" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="77564000" />
<option name="totallyTimeSpent" value="81063000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -607,7 +624,7 @@
<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.32912722" 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" />
@ -644,13 +661,6 @@
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/objtoobj.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2754">
<caret line="167" column="17" lean-forward="false" selection-start-line="167" selection-start-column="17" selection-end-line="167" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/db.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-289">
@ -771,13 +781,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2244">
<caret line="136" column="1" lean-forward="false" selection-start-line="136" selection-start-column="1" selection-end-line="136" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/func.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
@ -792,20 +795,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/context_base.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="12" column="29" lean-forward="false" selection-start-line="12" selection-start-column="29" selection-end-line="12" selection-end-column="29" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/objtoobj.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="7" lean-forward="false" selection-start-line="2" selection-start-column="7" selection-end-line="2" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/obj.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
@ -820,13 +809,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cache_memory.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="9" column="15" lean-forward="false" selection-start-line="9" selection-start-column="15" selection-end-line="9" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/context.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
@ -841,13 +823,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cache_db.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="10" column="15" lean-forward="false" selection-start-line="10" selection-start-column="15" selection-end-line="10" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://D:/app/go/src/runtime/hashmap.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4199">
@ -862,13 +837,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="389">
<caret line="59" column="18" lean-forward="false" selection-start-line="59" selection-start-column="18" selection-end-line="59" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="file://D:/app/go/src/errors/errors.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
@ -943,14 +911,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/var.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="18" column="24" lean-forward="false" selection-start-line="18" selection-start-column="24" selection-end-line="18" selection-end-column="24" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/error.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
@ -959,22 +919,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/const.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="17" column="22" lean-forward="false" selection-start-line="17" selection-start-column="4" selection-end-line="17" selection-end-column="22" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/session.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="969">
<caret line="57" column="13" lean-forward="false" selection-start-line="57" selection-start-column="13" selection-end-line="57" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/manage/manage.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="510">
@ -986,10 +930,96 @@
<entry file="file://$PROJECT_DIR$/config/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="17" column="1" lean-forward="true" selection-start-line="17" selection-start-column="1" selection-end-line="17" selection-end-column="1" />
<caret line="18" column="1" lean-forward="true" selection-start-line="18" selection-start-column="1" selection-end-line="18" selection-end-column="1" />
<folding>
<marker date="1504577466934" expanded="true" signature="201:235" ph="[...]" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/context_base.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="0" lean-forward="false" selection-start-line="9" selection-start-column="0" selection-end-line="16" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/var.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="18" column="24" lean-forward="false" selection-start-line="18" selection-start-column="24" selection-end-line="18" selection-end-column="24" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/const.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="13" lean-forward="false" selection-start-line="9" selection-start-column="4" selection-end-line="9" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/objtoobj.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
<caret line="32" column="5" lean-forward="false" selection-start-line="32" selection-start-column="5" selection-end-line="32" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/session.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="969">
<caret line="57" column="13" lean-forward="false" selection-start-line="57" selection-start-column="13" selection-end-line="57" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cache_memory.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="816">
<caret line="92" column="1" lean-forward="true" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cache_db.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-289">
<caret line="10" column="15" lean-forward="false" selection-start-line="10" selection-start-column="15" selection-end-line="10" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
<entry file="file://D:/app/go/src/internal/poll/fd_mutex.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="236" column="0" lean-forward="false" selection-start-line="236" selection-start-column="0" selection-end-line="236" 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="85">
<caret line="13" column="7" lean-forward="true" selection-start-line="13" selection-start-column="7" selection-end-line="13" selection-end-column="7" />
<folding>
<element signature="e#14#100#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="184">
<caret line="47" column="16" lean-forward="false" selection-start-line="47" selection-start-column="16" selection-end-line="47" selection-end-column="16" />
<folding>
<element signature="e#16#74#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>

View File

@ -1,4 +1,5 @@
{
"HOTIME-MAP": 1504577466932974800,
"cacheLongTime": 2592000,
"cacheShortTime": 7200,
"dbHost": "127.0.0.1",

View File

@ -1,41 +1,47 @@
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"go.hoteas.com/hotime"
"golang.org/x/net/websocket"
"time"
"fmt"
)
func main() {
appIns := hotime.Application{}
i := 0
a:=hotime.Map{}
a.Get("y")
for i:=0;i<300 ;i++ {
go func() {
for j:=0;j<30 ;j++ {
if j/2==0{
a.Put("x","1")
}else {
fmt.Println(a.GetInt64("x"))
}
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{}))
//快捷模式
//appIns.SetDefault(func(err ...*hotime.Error) *sql.DB {
}
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 {
// 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)
@ -44,42 +50,55 @@ func main() {
// }
// 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.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)
// },
// },
// },
//})
}

89
map.go
View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"reflect"
//"time"
)
//hotime的常用map
@ -11,86 +12,114 @@ type Map map[string]interface{}
//获取string
func (this Map) GetString(key string, err ...*Error) string {
return SafeMutex(this.GetTag(), func() interface{} {
if len(err) != 0 {
err[0].SetError(nil)
}
return ObjToStr((this)[key])
}).(string)
}
func (this *Map) Pointer() *Map{
func (this *Map) Pointer() *Map {
return this
}
//增加接口
func (this Map) Put(key string, value interface{}) {
//if this==nil{
// this=Map{}
//}
SafeMutex(this.GetTag(), func() interface{} {
this[key] = value
return nil
})
}
//删除接口
func (this Map) Delete(key string) {
SafeMutex(this.GetTag(), func() interface{} {
delete(this, key)
return nil
})
}
//唯一标志
func (this Map) GetTag() string {
//return SafeMutex(MUTEX_MAP, func() interface{} {
// if this[MUTEX_MAP] == nil {
// this[MUTEX_MAP] = ObjToStr(time.Now().UnixNano())
//
// }
// return ObjToStr(this[MUTEX_MAP])
//}).(string)
return MUTEX_MAP
}
//获取Int
func (this Map) GetInt(key string, err ...*Error) int {
return SafeMutex(this.GetTag(), func() interface{} {
v := ObjToInt((this)[key], err...)
return v
}).(int)
}
//获取Int
func (this Map) GetInt64(key string, err ...*Error) int64 {
return SafeMutex(this.GetTag(), func() interface{} {
v := ObjToInt64((this)[key], err...)
return v
}).(int64)
}
//获取Float64
func (this Map) GetFloat64(key string, err ...*Error) float64 {
return SafeMutex(this.GetTag(), func() interface{} {
v := ObjToFloat64((this)[key], err...)
return v
}).(float64)
}
func (this Map) GetSlice(key string, err ...*Error) Slice {
//var v Slice
res := SafeMutex(this.GetTag(), func() interface{} {
v := ObjToSlice((this)[key], err...)
return v
})
//var v Slice
if res != nil {
return res.(Slice)
}
return nil
}
func (this Map) GetMap(key string, err ...*Error) Map {
//var data Slice
res := SafeMutex(this.GetTag(), func() interface{} {
v := ObjToMap((this)[key], err...)
return v
})
//var v Slice
if res != nil {
return res.(Map)
}
return nil
}
func (this Map) Get(key string, err ...*Error) interface{} {
res := SafeMutex(this.GetTag(), func() interface{} {
if v, ok := (this)[key]; ok {
return v
}
@ -100,12 +129,17 @@ func (this Map) Get(key string, err ...*Error) interface{} {
err[0].SetError(e)
}
return nil
return nil
})
return res
}
//请传递指针过来
func (this Map) ToStruct(stct interface{}) {
SafeMutex(this.GetTag(), func() interface{} {
data := reflect.ValueOf(stct).Elem()
for k, v := range this {
ks := StrFirstToUpper(k)
@ -126,20 +160,27 @@ func (this Map) ToStruct(stct interface{}) {
dkey.Set(reflect.ValueOf(v))
}
}
return nil
})
}
func (this Map) ToJsonString() string {
res := SafeMutex(this.GetTag(), func() interface{} {
return ObjToStr(this)
})
return res.(string)
}
func (this Map) JsonToMap(jsonStr string,err... *Error) {
e:=json.Unmarshal([]byte(jsonStr), &this)
if e!=nil&&len(err)!=0{
func (this Map) JsonToMap(jsonStr string, err ...*Error) {
SafeMutex(this.GetTag(), func() interface{} {
e := json.Unmarshal([]byte(jsonStr), &this)
if e != nil && len(err) != 0 {
err[0].SetError(e)
}
return nil
})
}