Documentation ¶
Overview ¶
Package session includes session related manipulations.
Wide server side needs maintain two kinds of sessions:
- HTTP session: mainly used for login authentication
- Wide session: browser tab open/refresh will create one, and associates with HTTP session
When a session gone: release all resources associated with it, such as running processes, event queues.
Index ¶
- Constants
- Variables
- func CanAccess(userId, path string) bool
- func FixedTimeRelease()
- func FixedTimeReport()
- func FixedTimeSave()
- func GitHubUserInfo(accessToken string) (ret map[string]interface{})
- func GithubCallbackHandler(w http.ResponseWriter, r *http.Request)
- func LoginHandler(w http.ResponseWriter, r *http.Request)
- func LogoutHandler(w http.ResponseWriter, r *http.Request)
- func PreferenceHandler(w http.ResponseWriter, r *http.Request)
- func RedirectGitHubHandler(w http.ResponseWriter, r *http.Request)
- func RunHandler(w http.ResponseWriter, r *http.Request, channel map[string]*util.WSChannel)
- func SaveContentHandler(w http.ResponseWriter, r *http.Request)
- func SaveOnlineUsers()
- func StopHandler(w http.ResponseWriter, r *http.Request)
- func WSHandler(w http.ResponseWriter, r *http.Request)
- type WideSession
Constants ¶
const (
CookieName = "wide-sess"
)
Variables ¶
var ( // SessionWS holds all session channels. <sid, *util.WSChannel> SessionWS = map[string]*util.WSChannel{} // EditorWS holds all editor channels. <sid, *util.WSChannel> EditorWS = map[string]*util.WSChannel{} // OutputWS holds all output channels. <sid, *util.WSChannel> OutputWS = map[string]*util.WSChannel{} // NotificationWS holds all notification channels. <sid, *util.WSChannel> NotificationWS = map[string]*util.WSChannel{} // PlaygroundWS holds all playground channels. <sid, *util.WSChannel> PlaygroundWS = map[string]*util.WSChannel{} )
var HTTPSession = sessions.NewCookieStore([]byte("BEYOND"))
HTTP session store.
var Processes = procs{}
Processse of all users.
<sid, []*os.Process>
var WideSessions wSessions
Wide sessions.
Functions ¶
func CanAccess ¶
CanAccess determines whether the user specified by the given user id can access the specified path.
func FixedTimeRelease ¶
func FixedTimeRelease()
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).
Invalid sessions: sessions that not used within 30 minutes, refers to WideSession.Updated field.
func FixedTimeReport ¶
func FixedTimeReport()
FixedTimeReport reports the Wide sessions status periodically (10 minutes).
func FixedTimeSave ¶
func FixedTimeSave()
FixedTimeSave saves online users' configurations periodically (1 minute).
Main goal of this function is to save user session content, for restoring session content while user open Wide next time.
func GitHubUserInfo ¶
GitHubUserInfo returns GitHub user info specified by the given access token.
func GithubCallbackHandler ¶
func GithubCallbackHandler(w http.ResponseWriter, r *http.Request)
func LoginHandler ¶
func LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler handles request of show login page.
func LogoutHandler ¶
func LogoutHandler(w http.ResponseWriter, r *http.Request)
LogoutHandler handles request of user logout (exit).
func PreferenceHandler ¶
func PreferenceHandler(w http.ResponseWriter, r *http.Request)
PreferenceHandler handles request of preference page.
func RedirectGitHubHandler ¶
func RedirectGitHubHandler(w http.ResponseWriter, r *http.Request)
RedirectGitHubHandler redirects to GitHub auth page.
func RunHandler ¶
RunHandler handles request of executing a binary file.
func SaveContentHandler ¶
func SaveContentHandler(w http.ResponseWriter, r *http.Request)
SaveContentHandler handles request of session content string.
func SaveOnlineUsers ¶
func SaveOnlineUsers()
SaveOnlineUsers saves online users' configurations at once.
func StopHandler ¶
func StopHandler(w http.ResponseWriter, r *http.Request)
StopHandler handles request of stopping a running process.
Types ¶
type WideSession ¶
type WideSession struct { ID string // id UserId string // user id HTTPSession *sessions.Session // HTTP session related Processes []*os.Process // process set EventQueue *event.UserEventQueue // event queue State int // state Content *conf.LatestSessionContent // the latest session content FileWatcher *fsnotify.Watcher // files change watcher Created time.Time // create time Updated time.Time // the latest use time }
WideSession represents a session associated with a browser tab.
func (*WideSession) Refresh ¶
func (s *WideSession) Refresh()
Refresh refreshes the channel by updating its use time.
func (*WideSession) SetProcesses ¶
func (s *WideSession) SetProcesses(ps []*os.Process)
SetProcesses binds process set with the wide session.