session

package
v0.0.0-...-ef8be34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2014 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Session manipulations.

Wide server side needs maintain two kinds of sessions:

  1. HTTP session: mainly used for login authentication
  2. 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

View Source
const (
	SessionStateActive = iota // session state: active
	SessionStateClosed        // session state: closed (not used so far)
)
View Source
const (
	UserExists      = "user exists"
	UserCreated     = "user created"
	UserCreateError = "user create error"
)

Variables

View Source
var (
	// Session channels. <sid, *util.WSChannel>
	SessionWS = map[string]*util.WSChannel{}

	// Editor channels. <sid, *util.WSChannel>
	EditorWS = map[string]*util.WSChannel{}

	// Output channels. <sid, *util.WSChannel>
	OutputWS = map[string]*util.WSChannel{}

	// Notification channels. <sid, *util.WSChannel>
	NotificationWS = map[string]*util.WSChannel{}
)
View Source
var HTTPSession = sessions.NewCookieStore([]byte("BEYOND"))

HTTP session store.

Functions

func FixedTimeRelease

func FixedTimeRelease()

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 LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request)

LoginHandler handles request of user login.

func LogoutHandler

func LogoutHandler(w http.ResponseWriter, r *http.Request)

LogoutHandler handles request of user logout (exit).

func SaveContent

func SaveContent(w http.ResponseWriter, r *http.Request)

SaveContent handles request of session content storing.

func SignUpUser

func SignUpUser(w http.ResponseWriter, r *http.Request)

SignUpUser handles request of registering user.

func WSHandler

func WSHandler(w http.ResponseWriter, r *http.Request)

WSHandler handles request of creating session channel.

When a channel closed, releases all resources associated with it.

Types

type Sessions

type Sessions []*WideSession

Type of wide sessions.

var WideSessions Sessions

Wide sessions.

func (*Sessions) Get

func (sessions *Sessions) Get(sid string) *WideSession

Get gets a wide session with the specified session id.

func (*Sessions) GetByUsername

func (sessions *Sessions) GetByUsername(username string) []*WideSession

GetByUsername gets wide sessions.

func (*Sessions) New

func (sessions *Sessions) New(httpSession *sessions.Session, sid string) *WideSession

New creates a wide session.

func (*Sessions) Remove

func (sessions *Sessions) Remove(sid string)

Remove removes a wide session specified with the given session id, releases resources associated with it.

Session-related resources:

  1. user event queue
  2. process set
  3. websocket channels

type WideSession

type WideSession struct {
	Id          string                     // id
	Username    string                     // username
	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
	Created     time.Time                  // create time
	Updated     time.Time                  // the latest use time
}

Wide 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL