NewSession created and save new session to database.
(db *gorp.DbMap, expire int64)
| 280 | |
| 281 | // NewSession created and save new session to database. |
| 282 | func NewSession(db *gorp.DbMap, expire int64) (s *Session, err error) { |
| 283 | id := uuid.Must(uuid.NewV4()).String() |
| 284 | now := time.Now().Unix() |
| 285 | s = &Session{ |
| 286 | ID: id, |
| 287 | Created: now, |
| 288 | Expire: now + expire, |
| 289 | Store: gin.H{}, |
| 290 | } |
| 291 | |
| 292 | err = db.Insert(s) |
| 293 | if err != nil { |
| 294 | err = errors.Wrapf(err, "new session failed") |
| 295 | return |
| 296 | } |
| 297 | |
| 298 | return |
| 299 | } |
| 300 | |
| 301 | // GetSession returns session object of specified session id. |
| 302 | func GetSession(db *gorp.DbMap, id string) (s *Session, err error) { |
no test coverage detected