This commit is contained in:
parent
8763e6b83d
commit
f0b76f0d10
|
@ -19,9 +19,9 @@ import (
|
|||
|
||||
// 最后一次会话内容结构.
|
||||
type LatestSessionContent struct {
|
||||
FileTree []string // 文件树展开的路径集
|
||||
Files []string // 编辑器打开的文件路径集
|
||||
CurrentFile string // 当前编辑器文件路径
|
||||
FileTree []string `json:"fileTree"` // 文件树展开的路径集
|
||||
Files []string `json:"files"` // 编辑器打开的文件路径集
|
||||
CurrentFile string `json:"currentFile"` // 当前编辑器文件路径
|
||||
}
|
||||
|
||||
// 用户结构.
|
||||
|
|
4
main.go
4
main.go
|
@ -123,9 +123,9 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
// 创建一个 Wide 会话
|
||||
wideSession := session.WideSessions.New(httpSession)
|
||||
|
||||
wideSessions := session.WideSessions.GetByHTTPSession(httpSession)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
wideSessions := session.WideSessions.GetByUsername(username)
|
||||
userConf := conf.Wide.GetUser(username)
|
||||
|
||||
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(r), "locale": i18n.GetLocale(r),
|
||||
|
|
|
@ -220,7 +220,11 @@ func (sessions *Sessions) Get(sid string) *WideSession {
|
|||
return nil
|
||||
}
|
||||
|
||||
// 移除 Wide 会话.
|
||||
// 移除 Wide 会话,释放相关资源.
|
||||
// 会话相关资源:
|
||||
// 1. 用户事件队列
|
||||
// 2. 运行中的进程
|
||||
// 3. WebSocket 通道
|
||||
func (sessions *Sessions) Remove(sid string) {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
@ -273,32 +277,18 @@ func (sessions *Sessions) Remove(sid string) {
|
|||
}
|
||||
}
|
||||
|
||||
// 获取 HTTP 会话关联的所有 Wide 会话.
|
||||
func (sessions *Sessions) GetByHTTPSession(httpSession *sessions.Session) []*WideSession {
|
||||
// 获取 username 指定的用户的所有 Wide 会话.
|
||||
func (sessions *Sessions) GetByUsername(username string) []*WideSession {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
ret := []*WideSession{}
|
||||
|
||||
for _, s := range *sessions {
|
||||
if s.HTTPSession.ID == httpSession.ID {
|
||||
if s.Username == username {
|
||||
ret = append(ret, s)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// 移除 HTTP 会话关联的所有 Wide 会话.
|
||||
func (sessions *Sessions) RemoveByHTTPSession(httpSession *sessions.Session) {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
for i, s := range *sessions {
|
||||
if s.HTTPSession.ID == httpSession.ID {
|
||||
*sessions = append((*sessions)[:i], (*sessions)[i+1:]...)
|
||||
|
||||
glog.V(3).Infof("Has [%d] wide sessions currently", len(*sessions))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,13 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
// 创建一个 Wide 会话
|
||||
wideSession := session.WideSessions.New(httpSession)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(r), "locale": i18n.GetLocale(r),
|
||||
"session": wideSession}
|
||||
|
||||
wideSessions := session.WideSessions.GetByHTTPSession(httpSession)
|
||||
wideSessions := session.WideSessions.GetByUsername(username)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
glog.V(3).Infof("User [%s] has [%d] sessions", username, len(wideSessions))
|
||||
|
||||
t, err := template.ParseFiles("view/shell.html")
|
||||
|
|
|
@ -35,9 +35,9 @@ var session = {
|
|||
}, 5000);
|
||||
},
|
||||
restore: function () {
|
||||
var fileTree = config.latestSessionContent.FileTree,
|
||||
files = config.latestSessionContent.Files,
|
||||
currentFile = config.latestSessionContent.CurrentFile,
|
||||
var fileTree = config.latestSessionContent.fileTree,
|
||||
files = config.latestSessionContent.files,
|
||||
currentFile = config.latestSessionContent.currentFile,
|
||||
id = "",
|
||||
nodesToOpen = [];
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
<!--
|
||||
<li>
|
||||
<span>{{.i18n.debug}}</span>
|
||||
<div class="frame">
|
||||
|
@ -71,6 +72,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
-->
|
||||
<li>
|
||||
<span>{{.i18n.help}}</span>
|
||||
<div class="frame">
|
||||
|
|
Loading…
Reference in New Issue