コード例 #1
0
ファイル: feature_gate.go プロジェクト: earaujoassis/space
func Active(name string) bool {
	memstore.Start()
	defer memstore.Close()
	if featureExists, _ := redis.Bool(memstore.Do("HEXISTS", "feature.gates", name)); !featureExists {
		return false
	}
	return true
}
コード例 #2
0
ファイル: actions.go プロジェクト: earaujoassis/space
func RetrieveActionByToken(token string) Action {
	memstore.Start()
	defer memstore.Close()
	if indexExists, _ := redis.Bool(memstore.Do("HEXISTS", "models.actions.indexes", token)); !indexExists {
		return Action{}
	}
	actionUUID, _ := redis.String(memstore.Do("HGET", "models.actions.indexes", token))
	return RetrieveActionByUUID(actionUUID)
}
コード例 #3
0
ファイル: actions.go プロジェクト: earaujoassis/space
func (action *Action) Delete() {
	memstore.Start()
	defer memstore.Close()
	if actionExists, _ := redis.Bool(memstore.Do("HEXISTS", "models.actions", action.UUID)); !actionExists {
		return
	}
	memstore.Do("HDEL", "models.actions.indexes", action.Token)
	memstore.Do("HDEL", "models.actions", action.UUID)
	memstore.Do("ZREM", "models.actions.rank", action.UUID)
}
コード例 #4
0
ファイル: actions.go プロジェクト: earaujoassis/space
func RetrieveActionByUUID(uuid string) Action {
	var action Action
	memstore.Start()
	defer memstore.Close()
	if actionExists, _ := redis.Bool(memstore.Do("HEXISTS", "models.actions", uuid)); !actionExists {
		return Action{}
	}
	actionString, _ := redis.String(memstore.Do("HGET", "models.actions", uuid))
	if err := json.Unmarshal([]byte(actionString), &action); err != nil {
		return Action{}
	}
	return action
}
コード例 #5
0
ファイル: actions.go プロジェクト: earaujoassis/space
func (action *Action) Save() error {
	action.UserID = action.User.ID
	action.ClientID = action.Client.ID
	action.UUID = generateUUID()
	action.CreatedAt = time.Now().UTC()
	action.Token = GenerateRandomString(64)
	action.Moment = time.Now().UTC().Unix()
	action.ExpiresIn = shortestExpirationLength
	if err := validateModel("validate", action); err != nil {
		return err
	}
	memstore.Start()
	defer memstore.Close()
	actionJson, _ := json.Marshal(action)
	memstore.Do("HSET", "models.actions", action.UUID, actionJson)
	memstore.Do("HSET", "models.actions.indexes", action.Token, action.UUID)
	memstore.Do("ZADD", "models.actions.rank", action.Moment, action.UUID)
	return nil
}
コード例 #6
0
ファイル: checkers.go プロジェクト: earaujoassis/space
func SignInAttemptStatus(id string) string {
	memstore.Start()
	defer memstore.Close()

	if blockExists, _ := redis.Bool(memstore.Do("HEXISTS", "sign-in.blocked", id)); blockExists {
		return Blocked
	}
	if attemptExists, _ := redis.Bool(memstore.Do("HEXISTS", "sign-in.attempt", id)); attemptExists {
		reply, _ := redis.Int(memstore.Do("HGET", "sign-in.attempt", id))
		switch {
		case reply > 0 && reply <= attemptsUntilPreblock:
			return Clear
		case reply > attemptsUntilPreblock && reply <= attemptsUntilBlock:
			return Preblocked
		case reply > attemptsUntilBlock:
			return Blocked
		}
	}
	return Clear
}