chore: stabilize lint and verify builds

This commit is contained in:
2026-02-06 11:51:32 +08:00
parent edede17880
commit 1782f64417
114 changed files with 3032 additions and 1345 deletions

View File

@@ -15,12 +15,17 @@ type redisLimiterStorage struct {
prefix string
}
var (
errRateLimitRedisConfigNil = errors.New("rate limit redis config is nil")
errRateLimitRedisAddrsEmpty = errors.New("rate limit redis addrs is empty")
)
func newRedisLimiterStorage(config *RateLimitRedis) (fiber.Storage, error) {
if config == nil {
return nil, errors.New("rate limit redis config is nil")
return nil, errRateLimitRedisConfigNil
}
if len(config.Addrs) == 0 {
return nil, errors.New("rate limit redis addrs is empty")
return nil, errRateLimitRedisAddrsEmpty
}
client := redis.NewUniversalClient(&redis.UniversalOptions{
@@ -34,10 +39,12 @@ func newRedisLimiterStorage(config *RateLimitRedis) (fiber.Storage, error) {
defer cancel()
if err := client.Ping(ctx).Err(); err != nil {
_ = client.Close()
return nil, err
}
prefix := strings.TrimSpace(config.Prefix)
return &redisLimiterStorage{
client: client,
prefix: prefix,
@@ -52,6 +59,7 @@ func (s *redisLimiterStorage) GetWithContext(ctx context.Context, key string) ([
if errors.Is(err, redis.Nil) {
return nil, nil
}
return val, err
}
@@ -63,6 +71,7 @@ func (s *redisLimiterStorage) SetWithContext(ctx context.Context, key string, va
if s == nil || key == "" || len(val) == 0 {
return nil
}
return s.client.Set(ctx, s.key(key), val, exp).Err()
}
@@ -74,6 +83,7 @@ func (s *redisLimiterStorage) DeleteWithContext(ctx context.Context, key string)
if s == nil || key == "" {
return nil
}
return s.client.Del(ctx, s.key(key)).Err()
}
@@ -85,6 +95,7 @@ func (s *redisLimiterStorage) ResetWithContext(ctx context.Context) error {
if s == nil {
return nil
}
return s.client.FlushDB(ctx).Err()
}
@@ -96,6 +107,7 @@ func (s *redisLimiterStorage) Close() error {
if s == nil {
return nil
}
return s.client.Close()
}
@@ -103,5 +115,6 @@ func (s *redisLimiterStorage) key(raw string) string {
if s.prefix == "" {
return raw
}
return s.prefix + raw
}