Files
galaxy-game/lobby/internal/app/bootstrap.go
T
2026-04-26 20:34:39 +02:00

44 lines
1.4 KiB
Go

package app
import (
"context"
"fmt"
"galaxy/lobby/internal/config"
"galaxy/lobby/internal/telemetry"
"galaxy/redisconn"
"github.com/redis/go-redis/v9"
)
// newRedisClient builds the master Redis client from cfg via the shared
// `pkg/redisconn` helper. Replica clients are not opened in this iteration
// per ARCHITECTURE.md §Persistence Backends; they will be wired when read
// routing is introduced.
func newRedisClient(cfg config.RedisConfig) *redis.Client {
return redisconn.NewMasterClient(cfg.Conn)
}
// instrumentRedisClient attaches the OpenTelemetry tracing and metrics
// instrumentation to client when telemetryRuntime is available. The actual
// instrumentation lives in `pkg/redisconn` so every Galaxy service shares one
// surface.
func instrumentRedisClient(client *redis.Client, telemetryRuntime *telemetry.Runtime) error {
if client == nil {
return fmt.Errorf("instrument redis client: nil client")
}
if telemetryRuntime == nil {
return nil
}
return redisconn.Instrument(client,
redisconn.WithTracerProvider(telemetryRuntime.TracerProvider()),
redisconn.WithMeterProvider(telemetryRuntime.MeterProvider()),
)
}
// pingRedis performs a single Redis PING bounded by cfg.Conn.OperationTimeout
// to confirm that the configured Redis endpoint is reachable at startup.
func pingRedis(ctx context.Context, cfg config.RedisConfig, client *redis.Client) error {
return redisconn.Ping(ctx, client, cfg.Conn.OperationTimeout)
}