Exemplo n.º 1
0
func dbFromContext(c *gin.Context) *dbSession {
	iid, exists := c.Get("session_id")
	if exists {
		id := iid.(string)
		s := &dbSession{}
		err := models.DB.Where("s_id = ?", id).Find(s).Error
		if err == nil {
			s.decode()
			return s
		}
	}
	key, ok := dbHasSession(c)
	if ok {
		s := &dbSession{}
		err := models.DB.Where("s_id = ?", key).Find(s).Error
		if err == nil {
			s.decode()
			c.Set("session_id", key)
			return s
		}
	}
	ses := dbSessionInit(c)
	c.Set("session_id", ses.ID())
	return ses
}
Exemplo n.º 2
0
func imFromContext(c *gin.Context) *imSession {
	iid, exists := c.Get("session_id")
	if exists {
		id := iid.(string)
		ses, ok := mapSession[id]
		if ok {
			return ses
		}
	}
	key, ok := hasSession(c)
	if ok {
		ses, ok := mapSession[key]
		if ok {
			c.Set("session_id", key)
			return ses
		}
	}
	ses := sessionInit(c)
	c.Set("session_id", ses.ID())
	return ses
}