diff --git a/output/processes.go b/output/processes.go index 6572589..f25b380 100644 --- a/output/processes.go +++ b/output/processes.go @@ -38,7 +38,7 @@ func (procs *procs) add(wSession *session.WideSession, proc *os.Process) { mutex.Lock() defer mutex.Unlock() - sid := wSession.Id + sid := wSession.ID userProcesses := (*procs)[sid] userProcesses = append(userProcesses, proc) @@ -55,7 +55,7 @@ func (procs *procs) remove(wSession *session.WideSession, proc *os.Process) { mutex.Lock() defer mutex.Unlock() - sid := wSession.Id + sid := wSession.ID userProcesses := (*procs)[sid] @@ -80,7 +80,7 @@ func (procs *procs) kill(wSession *session.WideSession, pid int) { mutex.Lock() defer mutex.Unlock() - sid := wSession.Id + sid := wSession.ID userProcesses := (*procs)[sid] diff --git a/session/sessions.go b/session/sessions.go index b471751..e3193ab 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Session manipulations. +// Package session includes session related manipulations. // // Wide server side needs maintain two kinds of sessions: // @@ -40,30 +40,30 @@ import ( ) const ( - SessionStateActive = iota // session state: active - SessionStateClosed // session state: closed (not used so far) + sessionStateActive = iota + sessionStateClosed // (not used so far) ) var ( - // Session channels. + // SessionWS holds all session channels. SessionWS = map[string]*util.WSChannel{} - // Editor channels. + // EditorWS holds all editor channels. EditorWS = map[string]*util.WSChannel{} - // Output channels. + // OutputWS holds all output channels. OutputWS = map[string]*util.WSChannel{} - // Notification channels. + // NotificationWS holds all notification channels. NotificationWS = map[string]*util.WSChannel{} ) // HTTP session store. var HTTPSession = sessions.NewCookieStore([]byte("BEYOND")) -// Wide session, associated with a browser tab. +// WideSession represents a session associated with a browser tab. type WideSession struct { - Id string // id + ID string // id Username string // username HTTPSession *sessions.Session // HTTP session related Processes []*os.Process // process set @@ -75,14 +75,16 @@ type WideSession struct { } // Type of wide sessions. -type Sessions []*WideSession +type wSessions []*WideSession // Wide sessions. -var WideSessions Sessions +var WideSessions wSessions // Exclusive lock. var mutex sync.Mutex +// FixedTimeRelease releases invalid sessions. +// // In some special cases (such as a browser uninterrupted refresh / refresh in the source code view) will occur // some invalid sessions, the function checks and removes these invalid sessions periodically (1 hour). // @@ -95,9 +97,9 @@ func FixedTimeRelease() { for _, s := range WideSessions { if s.Updated.Before(threshold) { - glog.V(3).Infof("Removes a invalid session [%s], user [%s]", s.Id, s.Username) + glog.V(3).Infof("Removes a invalid session [%s], user [%s]", s.ID, s.Username) - WideSessions.Remove(s.Id) + WideSessions.Remove(s.ID) } } } @@ -261,7 +263,7 @@ func (s *WideSession) Refresh() { } // New creates a wide session. -func (sessions *Sessions) New(httpSession *sessions.Session, sid string) *WideSession { +func (sessions *wSessions) New(httpSession *sessions.Session, sid string) *WideSession { mutex.Lock() defer mutex.Unlock() @@ -271,11 +273,11 @@ func (sessions *Sessions) New(httpSession *sessions.Session, sid string) *WideSe userEventQueue := event.UserEventQueues.New(sid) ret := &WideSession{ - Id: sid, + ID: sid, Username: httpSession.Values["username"].(string), HTTPSession: httpSession, EventQueue: userEventQueue, - State: SessionStateActive, + State: sessionStateActive, Content: &conf.LatestSessionContent{}, Created: now, Updated: now, @@ -287,12 +289,12 @@ func (sessions *Sessions) New(httpSession *sessions.Session, sid string) *WideSe } // Get gets a wide session with the specified session id. -func (sessions *Sessions) Get(sid string) *WideSession { +func (sessions *wSessions) Get(sid string) *WideSession { mutex.Lock() defer mutex.Unlock() for _, s := range *sessions { - if s.Id == sid { + if s.ID == sid { return s } } @@ -307,12 +309,12 @@ func (sessions *Sessions) Get(sid string) *WideSession { // 1. user event queue // 2. process set // 3. websocket channels -func (sessions *Sessions) Remove(sid string) { +func (sessions *wSessions) Remove(sid string) { mutex.Lock() defer mutex.Unlock() for i, s := range *sessions { - if s.Id == sid { + if s.ID == sid { // remove from session set *sessions = append((*sessions)[:i], (*sessions)[i+1:]...) @@ -359,7 +361,7 @@ func (sessions *Sessions) Remove(sid string) { } // GetByUsername gets wide sessions. -func (sessions *Sessions) GetByUsername(username string) []*WideSession { +func (sessions *wSessions) GetByUsername(username string) []*WideSession { mutex.Lock() defer mutex.Unlock() diff --git a/session/users.go b/session/users.go index fb38c72..a6b3dad 100644 --- a/session/users.go +++ b/session/users.go @@ -32,15 +32,15 @@ import ( ) const ( - UserExists = "user exists" - UserCreated = "user created" - UserCreateError = "user create error" + userExists = "user exists" + userCreated = "user created" + userCreateError = "user create error" ) // Exclusive lock for adding user. var addUserMutex sync.Mutex -// PreferenceHandle handles request of preference page. +// PreferenceHandler handles request of preference page. func PreferenceHandler(w http.ResponseWriter, r *http.Request) { httpSession, _ := HTTPSession.Get(r, "wide-session") @@ -242,7 +242,7 @@ func SignUpUser(w http.ResponseWriter, r *http.Request) { password := args["password"].(string) msg := addUser(username, password) - if UserCreated != msg { + if userCreated != msg { succ = false data["msg"] = msg } @@ -260,7 +260,7 @@ func addUser(username, password string) string { for _, user := range conf.Wide.Users { if user.Name == username { - return UserExists + return userExists } } @@ -272,7 +272,7 @@ func addUser(username, password string) string { conf.Wide.Users = append(conf.Wide.Users, newUser) if !conf.Save() { - return UserCreateError + return userCreateError } conf.CreateWorkspaceDir(workspace) @@ -284,7 +284,7 @@ func addUser(username, password string) string { glog.Infof("Created a user [%s]", username) - return UserCreated + return userCreated } // helloWorld generates the 'Hello, 世界' source code in workspace/src/hello/main.go. diff --git a/views/index.html b/views/index.html index acc931c..8bceb13 100644 --- a/views/index.html +++ b/views/index.html @@ -476,7 +476,7 @@ "output": '{{.conf.OutputChannel}}', "session": '{{.conf.SessionChannel}}' }, - "wideSessionId": '{{.session.Id}}', + "wideSessionId": '{{.session.ID}}', "editorTheme": '{{.user.Editor.Theme}}', "latestSessionContent": {{.latestSessionContent}}, "editorTabSize": '{{.user.Editor.TabSize}}' diff --git a/views/shell.html b/views/shell.html index 9633b7e..9bff93f 100644 --- a/views/shell.html +++ b/views/shell.html @@ -19,7 +19,7 @@ channel: { shell: '{{.conf.ShellChannel}}' }, - wideSessionId: {{.session.Id}} + wideSessionId: {{.session.ID}} }; diff --git a/views/start.html b/views/start.html index 9001867..553d5e5 100644 --- a/views/start.html +++ b/views/start.html @@ -7,7 +7,7 @@
  • - {{.session.Id}} + {{.session.ID}}