Feat: session table and interface
This commit is contained in:
		| @@ -6,20 +6,25 @@ import ( | ||||
|  | ||||
| // each session contains the username of the user and the time at which it expires | ||||
| type Session struct { | ||||
| 	Username    string | ||||
| 	CurrentRoom string | ||||
| 	Expiry      time.Time | ||||
| 	ID uint32 | ||||
| 	// CurrentRoom string | ||||
| 	// Expiry      time.Time | ||||
| 	UpdatedAt   time.Time | ||||
| 	Lifetime    uint32 // minutes | ||||
| 	CookieToken string | ||||
| 	Username    string // username is playerid | ||||
| } | ||||
|  | ||||
| // we'll use this method later to determine if the session has expired | ||||
| func (s Session) IsExpired() bool { | ||||
| 	return s.Expiry.Before(time.Now()) | ||||
| 	return time.Now().After(s.UpdatedAt.Add(time.Minute * time.Duration(s.Lifetime))) | ||||
| 	// return s.Expiry.Before(time.Now()) | ||||
| } | ||||
|  | ||||
| func ListUsernames(ss map[string]*Session) []string { | ||||
| 	resp := make([]string, 0, len(ss)) | ||||
| 	for _, s := range ss { | ||||
| 		resp = append(resp, s.Username) | ||||
| 	} | ||||
| 	return resp | ||||
| } | ||||
| // func ListUsernames(ss map[string]*Session) []string { | ||||
| // 	resp := make([]string, 0, len(ss)) | ||||
| // 	for _, s := range ss { | ||||
| // 		resp = append(resp, s.Username) | ||||
| // 	} | ||||
| // 	return resp | ||||
| // } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder