优化多服务
This commit is contained in:
parent
fdc4a00176
commit
7423a7dd57
@ -5,12 +5,7 @@
|
|||||||
</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="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/GOPATH__hotime_.xml" afterPath="" />
|
|
||||||
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries" afterPath="" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/application.go" afterPath="$PROJECT_DIR$/application.go" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/objtoobj.go" afterPath="$PROJECT_DIR$/objtoobj.go" />
|
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/slice.go" afterPath="$PROJECT_DIR$/slice.go" />
|
|
||||||
</list>
|
</list>
|
||||||
<ignored path=".idea/dataSources.local.xml" />
|
<ignored path=".idea/dataSources.local.xml" />
|
||||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
@ -50,16 +45,6 @@
|
|||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file leaf-file-name="obj.go" pinned="false" current-in-tab="false">
|
|
||||||
<entry file="file://$PROJECT_DIR$/obj.go">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="85">
|
|
||||||
<caret line="5" column="15" lean-forward="false" selection-start-line="5" selection-start-column="15" selection-end-line="5" selection-end-column="15" />
|
|
||||||
<folding />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
</file>
|
|
||||||
<file leaf-file-name="manage.go" pinned="false" current-in-tab="false">
|
<file leaf-file-name="manage.go" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/manage/manage.go">
|
<entry file="file://$PROJECT_DIR$/manage/manage.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
@ -80,7 +65,7 @@
|
|||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file leaf-file-name="upload.go" pinned="false" current-in-tab="true">
|
<file leaf-file-name="upload.go" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/dri/upload/upload.go">
|
<entry file="file://$PROJECT_DIR$/dri/upload/upload.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="510">
|
<state relative-caret-position="510">
|
||||||
@ -92,6 +77,16 @@
|
|||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
|
<file leaf-file-name="index.html" pinned="false" current-in-tab="true">
|
||||||
|
<entry file="file://E:/work/hotimejs/index.html">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="391">
|
||||||
|
<caret line="23" column="7" lean-forward="true" selection-start-line="23" selection-start-column="7" selection-end-line="23" selection-end-column="7" />
|
||||||
|
<folding />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
<file leaf-file-name="config.json" pinned="false" current-in-tab="false">
|
<file leaf-file-name="config.json" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/example/config/config.json">
|
<entry file="file://$PROJECT_DIR$/example/config/config.json">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
@ -241,7 +236,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">
|
<component name="PropertiesComponent">
|
||||||
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
|
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
|
||||||
<property name="last_opened_file_path" value="E:/desktop/项目/大竹需求平台/golang" />
|
<property name="last_opened_file_path" value="E:/work/hotimejs/index.html" />
|
||||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||||
<property name="configurable.Global.GOPATH.is.expanded" value="true" />
|
<property name="configurable.Global.GOPATH.is.expanded" value="true" />
|
||||||
<property name="configurable.Project.GOPATH.is.expanded" value="true" />
|
<property name="configurable.Project.GOPATH.is.expanded" value="true" />
|
||||||
@ -434,7 +429,7 @@
|
|||||||
<workItem from="1504488391347" duration="840000" />
|
<workItem from="1504488391347" duration="840000" />
|
||||||
<workItem from="1504575702799" duration="11303000" />
|
<workItem from="1504575702799" duration="11303000" />
|
||||||
<workItem from="1504661068799" duration="698000" />
|
<workItem from="1504661068799" duration="698000" />
|
||||||
<workItem from="1508808650888" duration="41000" />
|
<workItem from="1508808650888" duration="210000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001">
|
<task id="LOCAL-00001">
|
||||||
<created>1500458878821</created>
|
<created>1500458878821</created>
|
||||||
@ -618,11 +613,18 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1504601110529</updated>
|
<updated>1504601110529</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="27" />
|
<task id="LOCAL-00027" summary="工具">
|
||||||
|
<created>1508808698714</created>
|
||||||
|
<option name="number" value="00027" />
|
||||||
|
<option name="presentableId" value="LOCAL-00027" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1508808698714</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="28" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TimeTrackingManager">
|
<component name="TimeTrackingManager">
|
||||||
<option name="totallyTimeSpent" value="89580000" />
|
<option name="totallyTimeSpent" value="89749000" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TodoView">
|
<component name="TodoView">
|
||||||
<todo-panel id="selected-file">
|
<todo-panel id="selected-file">
|
||||||
@ -635,8 +637,9 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ToolWindowManager">
|
<component name="ToolWindowManager">
|
||||||
<frame x="55" y="-8" width="1873" height="1084" extended-state="0" />
|
<frame x="55" y="-8" width="1873" height="1084" extended-state="0" />
|
||||||
|
<editor active="true" />
|
||||||
<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.34528404" 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.34528404" 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" />
|
||||||
@ -679,13 +682,6 @@
|
|||||||
<watches-manager />
|
<watches-manager />
|
||||||
</component>
|
</component>
|
||||||
<component name="editorHistoryManager">
|
<component name="editorHistoryManager">
|
||||||
<entry file="file://$PROJECT_DIR$/error.go">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="255">
|
|
||||||
<caret line="15" column="0" lean-forward="false" selection-start-line="15" selection-start-column="0" selection-end-line="15" selection-end-column="0" />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="-289">
|
<state relative-caret-position="-289">
|
||||||
@ -1025,5 +1021,13 @@
|
|||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry file="file://E:/work/hotimejs/index.html">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="391">
|
||||||
|
<caret line="23" column="7" lean-forward="true" selection-start-line="23" selection-start-column="7" selection-end-line="23" selection-end-column="7" />
|
||||||
|
<folding />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -22,9 +22,15 @@ type Application struct {
|
|||||||
configPath string
|
configPath string
|
||||||
Config Map
|
Config Map
|
||||||
Db HoTimeDB
|
Db HoTimeDB
|
||||||
|
Server *http.Server
|
||||||
CacheIns
|
CacheIns
|
||||||
sessionLong CacheIns
|
sessionLong CacheIns
|
||||||
sessionShort CacheIns
|
sessionShort CacheIns
|
||||||
|
http.Handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Application) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
this.handler(w, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
//启动实例
|
//启动实例
|
||||||
@ -50,7 +56,15 @@ func (this *Application) Run(router Router) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
run(this)
|
this.Server = &http.Server{}
|
||||||
|
if !IsRun {
|
||||||
|
IsRun = true
|
||||||
|
}
|
||||||
|
App[this.Port] = this
|
||||||
|
this.Server.Handler = this
|
||||||
|
//启动服务
|
||||||
|
this.Server.Addr = ":" + this.Port
|
||||||
|
this.Server.ListenAndServe()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +210,7 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
// 如果token存在就判断token是否在Session中有保存
|
// 如果token存在就判断token是否在Session中有保存
|
||||||
// 如果有取出token并复制给cookie
|
// 如果有取出token并复制给cookie
|
||||||
// 没有保存就生成随机的session
|
// 没有保存就生成随机的session
|
||||||
cookie, err := req.Cookie((Config["sessionName"]).(string))
|
cookie, err := req.Cookie((this.Config["sessionName"]).(string))
|
||||||
sessionId := Md5(strconv.Itoa(Rand(10)))
|
sessionId := Md5(strconv.Itoa(Rand(10)))
|
||||||
token := req.FormValue("token")
|
token := req.FormValue("token")
|
||||||
//isFirst:=false
|
//isFirst:=false
|
||||||
@ -207,7 +221,7 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
//else{
|
//else{
|
||||||
// isFirst=true;
|
// isFirst=true;
|
||||||
//}
|
//}
|
||||||
http.SetCookie(w, &http.Cookie{Name: Config["sessionName"].(string), Value: sessionId, Path: "/"})
|
http.SetCookie(w, &http.Cookie{Name: this.Config["sessionName"].(string), Value: sessionId, Path: "/"})
|
||||||
} else {
|
} else {
|
||||||
sessionId = cookie.Value
|
sessionId = cookie.Value
|
||||||
}
|
}
|
||||||
@ -250,13 +264,14 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//url赋值
|
//url赋值
|
||||||
path := Config.GetString("tpt") + o
|
path := this.Config.GetString("tpt") + o
|
||||||
|
|
||||||
//判断是否为默认
|
//判断是否为默认
|
||||||
if path[len(path)-1] == '/' {
|
if path[len(path)-1] == '/' {
|
||||||
defFile := Config["defFile"].([]string)
|
defFile := this.Config.GetSlice("defFile")
|
||||||
|
|
||||||
for i := 0; i < len(defFile); i++ {
|
for i := 0; i < len(defFile); i++ {
|
||||||
temp := path + defFile[i]
|
temp := path + defFile.GetString(i)
|
||||||
_, err := os.Stat(temp)
|
_, err := os.Stat(temp)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -50,13 +50,13 @@ func main() {
|
|||||||
"index": hotime.Ctr{
|
"index": hotime.Ctr{
|
||||||
"test": func(this *hotime.Context) {
|
"test": func(this *hotime.Context) {
|
||||||
fmt.Println(this.Db.GetTag())
|
fmt.Println(this.Db.GetTag())
|
||||||
x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
//x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||||
|
//
|
||||||
db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
// db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
||||||
|
//
|
||||||
return true
|
// return true
|
||||||
})
|
//})
|
||||||
this.Display(5, x)
|
this.Display(5, "dsadas")
|
||||||
},
|
},
|
||||||
"websocket": func(this *hotime.Context) {
|
"websocket": func(this *hotime.Context) {
|
||||||
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||||
|
21
func.go
21
func.go
@ -6,7 +6,6 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"net/http"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -183,7 +182,6 @@ func RandX(small int, max int) int {
|
|||||||
// GetDb()
|
// GetDb()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//复制返回数组
|
//复制返回数组
|
||||||
func DeepCopyMap(value interface{}) interface{} {
|
func DeepCopyMap(value interface{}) interface{} {
|
||||||
if valueMap, ok := value.(Map); ok {
|
if valueMap, ok := value.(Map); ok {
|
||||||
@ -300,23 +298,4 @@ func Round(f float64, n int) float64 {
|
|||||||
// CacheMemIns.Init(Config["cacheConfig"].(Map)["memory"].(CacheConfg).Time)
|
// CacheMemIns.Init(Config["cacheConfig"].(Map)["memory"].(CacheConfg).Time)
|
||||||
// CacheDBIns.Init(Config["cacheConfig"].(Map)["db"].(CacheConfg).Time)
|
// CacheDBIns.Init(Config["cacheConfig"].(Map)["db"].(CacheConfg).Time)
|
||||||
//}
|
//}
|
||||||
func run(a *Application) {
|
|
||||||
if !IsRun {
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
|
|
||||||
port:="80"
|
|
||||||
if IndexLastStr(req.Host, ":")!=-1{
|
|
||||||
port = Substr(req.Host, IndexLastStr(req.Host, ":")+1, len(req.Host))
|
|
||||||
}
|
|
||||||
|
|
||||||
if application[port] != nil {
|
|
||||||
application[port].handler(w, req)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
IsRun = true
|
|
||||||
}
|
|
||||||
|
|
||||||
application[a.Port] = a
|
|
||||||
http.ListenAndServe(":"+a.Port, nil)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -46,13 +46,13 @@ func Run() {
|
|||||||
"index": hotime.Ctr{
|
"index": hotime.Ctr{
|
||||||
"test": func(this *hotime.Context) {
|
"test": func(this *hotime.Context) {
|
||||||
fmt.Println(this.Db.GetTag())
|
fmt.Println(this.Db.GetTag())
|
||||||
x := this.Db.Action(func(db hotime.HoTimeDB) bool {
|
//x := this.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||||
|
//
|
||||||
db.Insert("user", hotime.Map{"unickname": "dasdas"})
|
// db.Insert("user", hotime.Map{"unickname": "dasdas"})
|
||||||
|
//
|
||||||
return true
|
// return true
|
||||||
})
|
//})
|
||||||
this.Display(5, x)
|
this.Display(0, 1)
|
||||||
},
|
},
|
||||||
"websocket": func(this *hotime.Context) {
|
"websocket": func(this *hotime.Context) {
|
||||||
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||||
|
@ -46,6 +46,12 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
|
|||||||
v = obj.(Slice)
|
v = obj.(Slice)
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
v = obj.([]interface{})
|
v = obj.([]interface{})
|
||||||
|
case []string:
|
||||||
|
v = Slice{}
|
||||||
|
for i := 0; i < len(obj.([]string)); i++ {
|
||||||
|
v = append(v, obj.([]string)[i])
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
v = nil
|
v = nil
|
||||||
err = errors.New("没有合适的转换对象!")
|
err = errors.New("没有合适的转换对象!")
|
||||||
|
2
var.go
2
var.go
@ -10,7 +10,7 @@ import "sync"
|
|||||||
var mutex = map[interface{}]*sync.RWMutex{} //安全锁
|
var mutex = map[interface{}]*sync.RWMutex{} //安全锁
|
||||||
var mutexer = sync.RWMutex{} //读写锁
|
var mutexer = sync.RWMutex{} //读写锁
|
||||||
var IsRun = false //当前状态
|
var IsRun = false //当前状态
|
||||||
var application = map[string]*Application{} //整个项目
|
var App = map[string]*Application{} //整个项目
|
||||||
|
|
||||||
//var Db = HoTimeDB{} //数据库实例
|
//var Db = HoTimeDB{} //数据库实例
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user