wide/user/sessions.go

40 lines
727 B
Go
Raw Normal View History

2014-08-31 13:39:39 +04:00
package user
import (
2014-09-16 19:58:52 +04:00
"math/rand"
"strconv"
"time"
2014-08-31 13:39:39 +04:00
"github.com/gorilla/sessions"
)
2014-09-16 19:58:52 +04:00
const (
SessionStateActive = iota // 会话状态:活的
)
// 用户 HTTP 会话,用于验证登录.
2014-08-31 13:39:39 +04:00
var Session = sessions.NewCookieStore([]byte("BEYOND"))
2014-09-16 19:58:52 +04:00
// Wide 会话,对应一个浏览器 tab.
type WideSession struct {
Id string // 唯一标识
State int // 状态
Created time.Time // 创建时间
Updated time.Time // 最近一次使用时间
}
// 创建一个 Wide 会话.
func NewSession() *WideSession {
rand.Seed(time.Now().UnixNano())
id := strconv.Itoa(rand.Int())
now := time.Now()
return &WideSession{
Id: id,
State: SessionStateActive,
Created: now,
Updated: now,
}
}