- env_helpers.go: getEnv*, parseLogAggregationLabels - db_init.go: initDatabaseWithRetry - redis_init.go: initRedis, filteredRedisLogger - rabbitmq.go: getRabbitMQURL - cors.go: CORS, cookies - rate_limit.go: rate limit defaults - services_init.go: initServices - middlewares_init.go: initMiddlewares, SetupMiddleware - config.go réduit de ~1487 à ~550 LOC
45 lines
1 KiB
Go
45 lines
1 KiB
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// initRedis initialise la connexion Redis
|
|
func initRedis(redisURL string, logger *zap.Logger) (*redis.Client, error) {
|
|
opts, err := redis.ParseURL(redisURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Configurer un logger filtré pour Redis pour éviter les warnings "maint_notifications"
|
|
redis.SetLogger(&filteredRedisLogger{logger: logger})
|
|
|
|
client := redis.NewClient(opts)
|
|
|
|
// Test de connexion
|
|
ctx := context.Background()
|
|
_, err = client.Ping(ctx).Result()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return client, nil
|
|
}
|
|
|
|
// filteredRedisLogger est un wrapper pour filtrer les logs de Redis
|
|
type filteredRedisLogger struct {
|
|
logger *zap.Logger
|
|
}
|
|
|
|
func (l *filteredRedisLogger) Printf(ctx context.Context, format string, v ...interface{}) {
|
|
msg := fmt.Sprintf(format, v...)
|
|
if strings.Contains(msg, "maint_notifications") {
|
|
return // Ignorer ce warning spécifique en mode auto-discovery
|
|
}
|
|
l.logger.Debug("Redis internal", zap.String("message", msg))
|
|
}
|