// Get the current signed in user func GetSignedInUser(r *http.Request) *account.SignedUser { user := context.Get(r, context.SIGNEDID) if user == nil { return nil } return user.(*account.SignedUser) }
func IsSignedInUser(r *http.Request) bool { user := context.Get(r, context.SIGNEDID) if user == nil { return false } return true }
// Need request object, for reading session id from request context func InsertData(r *http.Request, key string, value interface{}) { sid := context.Get(r, context.SID).(string) c := redis.Get() if _, err := c.Do("HMSET", sid, key, value); err != nil { panic(err.Error()) } // Session storage id will be remove in 10 hours. Keep // redis database clean. c.Do("EXPIREAT", sid, time.Now().Add(time.Hour*10).Unix()) }
// If value is not found, then return empty string func ReadData(r *http.Request, key string) (interface{}, error) { var value string sid := context.Get(r, context.SID).(string) c := redis.Get() raw, err := redigo.Values(c.Do("HMGET", sid, key)) redigo.Scan(raw, &value) if err != nil { return nil, err } return value, nil }
func DeleteData(r *http.Request, key string) { sid := context.Get(r, context.SID).(string) c := redis.Get() c.Do("HDEL", sid, key) }
func GetLang(r *http.Request) string { return context.Get(r, context.LANGUAGE).(string) }